// Inspired by: https://rickandmorty.fandom.com/wiki/Butter_Robot#:~:text=Moments%20after%20completing%20its%20task,to%20the%20club%2C%20pal.%22 // Pins addressing according to the attiny412 datasheet const byte ledPin = PIN_PA3; const byte btnPin = PIN_PA7; // https://www.arduino.cc/reference/en/language/variables/variable-scope-qualifiers/volatile/ // Volatile is to be used when the value is changed by something out side of the code itself. // Probably not needed in this project =) // LEDstate to write to ledPin volatile byte LEDstate = LOW; // States for minimalistic debouncing int lastState = HIGH; int currentState; // Boolean to disable main loop while the "conversation" takes place. bool conversation = false; void setup() { // Setting up the serial communcations. // The Serial.swap(1) function moves TX/RX communcations to the pins used on the board Serial.swap(1); Serial.begin(115200); Serial.println("Hello...!"); // Setting modes of the pins. // ledPin will provide power to the led, so it's an output // The button will connect to ground, so we use the built in pullup to detect it pinMode(ledPin, OUTPUT); pinMode(btnPin, INPUT_PULLUP); // Initial state of the LED digitalWrite(ledPin, LEDstate); } void loop() { // Read the value of the button currentState = digitalRead(btnPin); // If the button was just pushed, start the "converstation" if (lastState == HIGH && currentState == LOW){ revealPurpose(); conversation = true; } else if (lastState == LOW && currentState == HIGH){ // End the converstion on a sarcastic note when // the button has been released sarcasticAndMundane(); conversation = false; } // If there not an ongoing conversation, // fulfill your purpose! if(!conversation){ LEDstate = !LEDstate; digitalWrite(ledPin, LEDstate); ask(); } lastState = currentState; } void ask(){ Serial.println("What is my purpose?"); delay(500); } void revealPurpose() { Serial.println("Your purpose is to blink a LED."); flicker(); Serial.println("Oh my god..."); flicker(); } // Flash the light fast, just for fun void flicker(){ for(int i = 0; i < 10; i++){ digitalWrite(ledPin, HIGH); delay(80); digitalWrite(ledPin, LOW); delay(80); } delay(800); } void sarcasticAndMundane(){ Serial.println("Yeah, welcome to the club, pal."); flicker(); }