#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// If using software SPI (the default case):
#define OLED_MOSI 11 //D1
#define OLED_CLK 12 //D0
#define OLED_DC 9
#define OLED_CS 8
#define OLED_RESET 10
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
const char MorseTree[] = {'\0','E', 'T', 'I', 'A', 'N', 'M', 'S',
'U', 'R', 'W', 'D', 'K', 'G', 'O', 'H',
'V', 'F', 'U', 'L', 'A', 'P', 'J', 'B',
'X', 'C', 'Y', 'Z', 'Q', '\0','\0','5',
'4', '\0','3', '\0','\0','\0','2', '\0',
'\0','+', '\0','\0','\0','\0','1', '6',
'=', '/', '\0','\0','\0','(', '\0','7',
'\0','\0','\0','8', '\0','9', '0', '\0',
'\0','\0','\0','\0','\0','\0','\0','\0',
'\0','\0','\0','?', '_', '\0','\0','\0',
'\0','"', '\0','\0','.', '\0','\0','\0',
'\0','@', '\0','\0','\0','\0','\0','\0',
'-', '\0','\0','\0','\0','\0','\0','\0',
'\0',';', '!', '\0',')', '\0','\0','\0',
'\0','\0',',', '\0','\0','\0','\0',':',
'\0','\0','\0','\0','\0','\0','\0'
};
int val = 0; // A Variable to Store the Light Value from the LDR
int ctrHigh = 0;
int ctrLow = 0;
int codePtr = 0;
int dotLen;
bool Bflag;
int wpm;
static unsigned long thisMicros = 0;
static unsigned long lastMicros = 0;
void setup()
{
display.begin(SSD1306_SWITCHCAPVCC);
display.display();
delay(1000);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
Serial.begin(9600);// Start a Serial Connection
Serial.print(codePtr);
}
void loop()
{
getMorse();
}
void dis(){
display.display();
lastMicros = thisMicros;
thisMicros = micros();
}
void getMorse(){
wpm = (analogRead(2)*10)/1023 ;
val = analogRead(1);
///////////////////
if (wpm == 1){
dotLen = 63;
}
if (wpm == 2){
dotLen = 125;
}
if (wpm == 3){
dotLen = 187;
}
if (wpm == 4){
dotLen = 250;
}
if (wpm == 5){
dotLen = 312;
}
if (wpm == 6){
dotLen = 375;
}
if (wpm == 7){
dotLen = 737;
}
if (wpm == 8){
dotLen = 500;
}
if (wpm == 9){
dotLen = 562;
}
if (wpm == 10){
dotLen = 625;
}
////////////////////
// Serial.println(wpm);
if (val >= 300)
{
ctrHigh++;
ctrLow = 0;
// digitalWrite(13, HIGH);
// tone(9, 1000);
} else {
ctrLow++;
if ((ctrHigh >= dotLen) && (ctrHigh < dotLen*2)) {
// Serial.print(".");
Bflag =true;
codePtr = (2*codePtr) + 1;
} else if (ctrHigh >= dotLen * 2) {
Bflag =true;
// Serial.print("-");
codePtr = (2*codePtr) + 2;
} else {
if(ctrLow >= dotLen*6 && Bflag == true){
Serial.print(" ");
display.print(" ");
Bflag = false;
}
if(ctrLow >= dotLen*14){
display.clearDisplay();
display.setCursor(0,0);
}
if(ctrLow == dotLen*2){
Serial.print(MorseTree[codePtr]);
display.print(MorseTree[codePtr]);
dis();
codePtr = 0;
}
}
ctrHigh = 0;
// digitalWrite(13, LOW);
// noTone(9);
}
}
Comments