/* 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. added button for mic control - Chuma Asuzu, Fab Academy 2019*/ #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 buttonPin = 3; int buttonState = 0; const int analogInPin = 7; // Analog input pin that the mic is attached to, 7 for Chuma's design 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 buttonState = digitalRead(buttonPin); if (buttonState == LOW) { sensorValue = analogRead(analogInPin); outputValue = map(sensorValue, 0, 1023, 0, 255); serial.println(outputValue); } else { serial.println("no output"); } delay(10); // delay at 100 miliseconds in between reads for stability }