#define button 1 // PA5 #define led 10 // PA3 void short_delay() { delay(250); } void long_delay() { delay(750); } void short_beep() { digitalWrite(led, HIGH); short_delay(); digitalWrite(led, LOW); } void long_beep() { digitalWrite(led, HIGH); long_delay(); digitalWrite(led, LOW); } // based on Morse code chart: http://www.sckans.edu/~sireland/radio/code.html void up(){ // U short_beep(); short_delay(); short_beep(); short_delay(); long_beep(); long_delay(); // P short_beep(); short_delay(); long_beep(); short_delay(); long_beep(); short_delay(); short_beep(); long_delay(); } void down(){ // D long_beep(); short_delay(); short_beep(); short_delay(); short_beep(); long_delay(); // O long_beep(); short_delay(); long_beep(); short_delay(); long_beep(); long_delay(); // W short_beep(); short_delay(); long_beep(); short_delay(); long_beep(); long_delay(); // N long_beep(); short_delay(); short_beep(); long_delay(); } void left(){ // L short_beep(); short_delay(); long_beep(); short_delay(); short_beep(); short_delay(); short_beep(); long_delay(); // E short_beep(); long_delay(); // F short_beep(); short_delay(); short_beep(); short_delay(); long_beep(); short_delay(); short_beep(); long_delay(); // T long_beep(); long_delay(); } void right(){ // R short_beep(); short_delay(); long_beep(); short_delay(); long_delay(); // I short_beep(); short_delay(); short_beep(); long_delay(); // G long_beep(); short_delay(); long_beep(); short_delay(); short_beep(); long_delay(); // H short_beep(); short_delay(); short_beep(); short_delay(); short_beep(); short_delay(); short_beep(); long_delay(); // T long_beep(); long_delay(); } void setup() { // put your setup code here, to run once: pinMode(led, OUTPUT); pinMode(button, INPUT); Serial.begin(9600); digitalWrite(led, HIGH); while(!Serial.available()); // wait for serial String retrieve = Serial.readString(); digitalWrite(led, LOW); } void loop() { // put your main code here, to run repeatedly: if(Serial.available()) { int result = Serial.parseInt(); switch(result) { case 0: up(); break; case 1: down(); break; case 2: left(); break; case 3: right(); break; } while(Serial.available()) { Serial.read(); // empty buffer } } }