Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite3d77e3

Browse files
committed
added partial morse display
1 parent1792de0 commite3d77e3

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

‎examples/FirebaseMorse_ESP8266/FirebaseMorse_ESP8266.ino

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
#defineWIFI_SSID"SSID"
2424
#defineWIFI_PASSWORD"PASSWORD"
2525

26+
constint shortMillis =500;
27+
constint longMillis = shortMillis *3;
28+
2629
// We define morse . to be binary 0 and - to be binary 1. The longest letter
2730
// is 5 morse elements long so we would have a sparse array of 2^5=32. But
2831
// we need to add a leading 1 to ensure that .- and ..- are not the same value.
@@ -35,7 +38,7 @@ Adafruit_SSD1306 display(oledResetPin);
3538

3639
constint morseButtonPin =2;
3740

38-
voidupdateDisplay(const String& message,constchar& indicator);
41+
voidupdateDisplay(const String& message,constchar& indicator,int code);
3942
voidinitializeMorseToChar();
4043

4144
voidsetup() {
@@ -59,21 +62,18 @@ void setup() {
5962
Serial.println(WiFi.localIP());
6063
}
6164

62-
constint shortMillis =500;
63-
constint longMillis = shortMillis *3;
64-
6565
String currentMessage;
6666
int currentLetter;
6767
voidloop() {
6868
// Wait while button is up.
6969
int upStarted =millis();
7070
while (digitalRead(morseButtonPin) == HIGH) {
7171
if (millis() - upStarted > longMillis) {
72-
updateDisplay(currentMessage,'w');
72+
updateDisplay(currentMessage,'w', currentLetter);
7373
}elseif (millis() - upStarted > shortMillis) {
74-
updateDisplay(currentMessage,'l');
74+
updateDisplay(currentMessage,'l', currentLetter);
7575
}else {
76-
updateDisplay(currentMessage,'');
76+
updateDisplay(currentMessage,'', currentLetter);
7777
}
7878
delay(1);
7979
}
@@ -99,11 +99,11 @@ void loop() {
9999
// Wait while button is down.
100100
while (digitalRead(morseButtonPin) == LOW) {
101101
if (millis() - pressStarted > longMillis) {
102-
updateDisplay(currentMessage,'-');
102+
updateDisplay(currentMessage,'-', currentLetter);
103103
}elseif (millis() - pressStarted > shortMillis) {
104-
updateDisplay(currentMessage,'.');
104+
updateDisplay(currentMessage,'.', currentLetter);
105105
}else {
106-
updateDisplay(currentMessage,'');
106+
updateDisplay(currentMessage,'', currentLetter);
107107
}
108108
delay(1);
109109
}
@@ -114,20 +114,25 @@ void loop() {
114114
}
115115
}
116116

117-
voidupdateDisplay(const String& message,constchar& indicator) {
117+
voidupdateDisplay(const String& message,constchar& indicator,int code) {
118118
display.clearDisplay();
119119
display.setTextSize(2);
120120
display.setTextColor(WHITE);
121121
display.setCursor(0,0);
122122
display.println(message);
123123

124124
display.setTextSize(1);
125+
display.setCursor(0, display.height() -10);
126+
constint mask =1;
127+
while (code >1) {
128+
display.print((code&mask) ?'-' :'.');
129+
code = code >>1;
130+
}
125131
display.setCursor(display.width() -10, display.height() -10);
126132
display.print(indicator);
127133
display.display();
128134
}
129135

130-
131136
voidinitializeMorseToChar() {
132137
morseToChar[B101] ='a';
133138
morseToChar[B11000] ='b';

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp