Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.57 KB | None | 0 0
  1. const int LDR = A0;
  2. int counter = 0;
  3. String morse = "";
  4.  
  5. void setup() {
  6.   pinMode (LDR, INPUT);
  7. }
  8.  
  9. void loop() {
  10.   int value = analogRead(LDR);
  11.   if (value > 250) {
  12.     counter++;
  13.   } else {
  14.     counter = 0;
  15.   }
  16.   delay(300);
  17.   if (counter == 1) {
  18.     addDot();
  19.   } else if (counter == 3) {
  20.     removeDot();
  21.     addDash();
  22.   }
  23.   Serial.println(morse);
  24. }
  25.  
  26. void addDot() {
  27.   morse += ".";
  28. }
  29.  
  30. void addDash() {
  31.   morse += "-";
  32. }
  33.  
  34. void removeDot() {
  35.   int length = morse.length();
  36.   if (morse.substring(length) == ".") {
  37.     morse.remove(length);
  38.   }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement