/* The code sourced from FunDuino from below link http://funduino.blogspot.com/2012/02/attiny45-software-serial.html ----------------------------------- modified by Darshan Shah, during Fab Academy 2018. - Mic pin has been modified. */ #include // include serial library #define rxPin 0 // the pin on which to receive serial data #define txPin 1 // the pin on which to transmit serial data const int analogInPin = 3; // Analog input pin that the mic is attached to int sensorValue = 0; // variable to store the value coming from the mic sensor int outputValue = 0; // variable to store the output value to the PWM (analog out) SoftwareSerial serial(rxPin, txPin); // serial communication void setup() { // the setup routine once we start pinMode(rxPin, INPUT_PULLUP); //sets the rxPin as input pinMode(txPin, OUTPUT); //sets the txPin as output serial.begin(115200); // to initialize the communication at 115200 bits per second } void loop() { // the loop routine runs over and over again forever sensorValue = analogRead(analogInPin); // reads the value from the specified pin outputValue = map(sensorValue, 0, 1023, 0, 255); // maps the value between the specified range // the following commands prints the value on the serial monitor or the serial plotter serial.print("sensor = " ); // print out the text as it is serial.print(sensorValue); // print out the sensor value you read serial.print("\t output = "); // print out the text as it is serial.println(outputValue); // print out the output value you read delay(100); // delay at 100 miliseconds in between reads for stability }