const int ledPins[] = {26, 27, 28, 29, 6, 7, 0, 1, 2, 4}; const int numLEDs = 10; const int buttonPin = 3; int buttonState = 0; bool statusButton = false; int buffer = 0; int blank = 0; int towTime = 2; String letter = ""; void setup() { for (int i = 0; i < numLEDs; i++) { pinMode(ledPins[i], OUTPUT); } pinMode(buttonPin, INPUT); } char convertMorseCharToLetter(String morseChar) { // All the alphabet in morse const char* morseLetters[] = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", "-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----.", ""}; for (int i = 0; i < 37; i++) { if (morseChar == morseLetters[i]) { // If there is a character if (i == 36) { // If it's empty return ' '; } else { return char('A' + i); // Return the code ASCII from 'A' to the index } } } return '?'; // If not found } void loop() { for (int i = numLEDs - 1; i > 0; i--) { // Take the LED one by one by searching their position on LedPins digitalWrite(ledPins[i], digitalRead(ledPins[i - 1])); // set the correct state } if(statusButton || towTime == 1 || towTime == 2){ // if the button is engage, the first led is ON, otherwise the led is OFF digitalWrite(ledPins[0], 1); statusButton = 0; towTime +=1; } else digitalWrite(ledPins[0], 0); delay(100); buttonState = digitalRead(buttonPin); // read if the button in engage if(buttonState == 1){ buffer +=1; blank = 0; } else //compt the empty time blank+=1; if(buttonState == 0 && buffer != 0){ // if the button is pressed a sufficient ammont of time if(buffer == 1 || buffer == 2){ // simple click statusButton = 1; buffer = 0; letter += String("."); } if(buttonState == 0 && buffer >2){ // long click statusButton = 1; buffer = 0; towTime = 0; letter += String("-"); } } if(blank > 15){ blank = 0; Serial.print(convertMorseCharToLetter(letter)); letter = ""; } } /* Serial.print("ici "); Serial.print(i);Serial.println(ledPins[i-1]); buttonState = digitalRead(buttonPin); // check if the pushbutton is pressed. If it is, the buttonState is HIGH: if (buttonState == HIGH) { // turn LED on: digitalWrite(ledPin, HIGH); } else { // turn LED off: digitalWrite(ledPin, LOW); } digitalWrite(26, HIGH); digitalWrite(27, HIGH); digitalWrite(28, HIGH); digitalWrite(29, HIGH); digitalWrite(6, HIGH); digitalWrite(7, HIGH); digitalWrite(0, HIGH); digitalWrite(2, HIGH); digitalWrite(1, HIGH); digitalWrite(4, HIGH); delay(1000); digitalWrite(26, LOW); digitalWrite(27, LOW); digitalWrite(28, LOW); digitalWrite(29, LOW); digitalWrite(6, LOW); digitalWrite(7, LOW); digitalWrite(0, LOW); digitalWrite(4, LOW); digitalWrite(2, LOW); digitalWrite(1, LOW); delay(1000);*/