Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int LDR = A0;
- int counter = 0;
- String morse = "";
- void setup() {
- pinMode (LDR, INPUT);
- }
- void loop() {
- int value = analogRead(LDR);
- if (value > 250) {
- counter++;
- } else {
- counter = 0;
- }
- delay(300);
- if (counter == 1) {
- addDot();
- } else if (counter == 3) {
- removeDot();
- addDash();
- }
- Serial.println(morse);
- }
- void addDot() {
- morse += ".";
- }
- void addDash() {
- morse += "-";
- }
- void removeDot() {
- int length = morse.length();
- if (morse.substring(length) == ".") {
- morse.remove(length);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement