// Include the SoftwareSerial library to run serial on Attiny45 #include // Define the RX and TX pins. #define TX 2 // PB3, Pin 2 on attiny45 leg #define RX 3 // PB4, Pin 3 on attiny45 leg SoftwareSerial mySerial(RX, TX); int buttonPin = PB2; // the number of the pushbutton pin int ledPin = PB1; // the number of the LED pin int buttonState = 0; // variable for reading the pushbutton status void setup() { // initialize serial communications at 9600 bps: mySerial.begin(9600); pinMode(buttonPin,INPUT); pinMode(ledPin, OUTPUT); } void loop() { buttonState = digitalRead(buttonPin); if (buttonState == 1) { digitalWrite(ledPin, LOW); mySerial.write(2); // mySerial.println("pressed"); delay(50); } else { int buttonState = 0; digitalWrite(ledPin, HIGH); mySerial.write(1); // mySerial.println("not pressed"); delay(50); } }