Ishita Bose / Mbed 2 deprecated LightMorseCode

Dependencies:   TextLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
ibose3
Date:
Wed Oct 21 18:06:05 2015 +0000
Commit message:
Takes in light from a photocell and translates it to English characters on an LCD Screen

Changed in this revision

MorseCode.cpp Show annotated file Show diff for this revision Revisions of this file
MorseCode.h Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MorseCode.cpp	Wed Oct 21 18:06:05 2015 +0000
@@ -0,0 +1,128 @@
+#include "mbed.h"
+#include "TextLCD.h"
+
+TextLCD lcd(p14, p16, p17, p18, p19, p20); 
+
+int Value = 0;
+int First = 1;
+int printSignal = 0;
+int clearSignal = 0;
+
+void printChar(int val) {
+    switch(val) {
+    case 0:
+        break;
+    case 184:
+        lcd.putc('a');
+        break;
+    case 3752:
+        lcd.putc('b');
+        break;
+    case 15080:
+        lcd.putc('c');
+        break;
+    case 936:
+        lcd.putc('d');
+        break;
+    case 8:
+        lcd.putc('e');
+        break;
+    case 2792:
+        lcd.putc('f');
+        break;
+    case 3816:
+        lcd.putc('g');
+        break;
+    case 680:
+        lcd.putc('h');
+        break;
+    case 40:
+        lcd.putc('i');
+        break;
+    case 48056:
+        lcd.putc('j');
+        break;
+    case 3768:
+        lcd.putc('k');
+        break;
+    case 2984:
+        lcd.putc('l');
+        break;
+    case 952:
+        lcd.putc('m');
+        break;
+    case 232:
+        lcd.putc('n');
+        break;
+    case 15288:
+        lcd.putc('o');
+        break;
+    case 12008:
+        lcd.putc('p');
+        break;
+    case 61112:
+        lcd.putc('q');
+        break;
+    case 744:
+        lcd.putc('r');
+        break;
+    case 168:
+        lcd.putc('s');
+        break;
+    case 56:
+        lcd.putc('t');
+        break;
+    case 696:
+        lcd.putc('u');
+        break;
+    case 2744:
+        lcd.putc('v');
+        break;
+    case 3000:
+        lcd.putc('w');
+        break;
+    case 15032:
+        lcd.putc('x');
+        break;
+    case 60344:
+        lcd.putc('y');
+        break;
+    case 15272:
+        lcd.putc('z');
+        break;
+    }
+}
+
+void MorseCode(int tick) {
+    if(tick) {
+        printSignal = 0;
+        clearSignal = 0;
+        
+        Value = Value << 1;
+        Value += 1;
+    }
+    else {
+        printSignal += 1;
+        clearSignal += 1;
+        
+        Value = Value << 1;
+    }
+    
+    if(First) {
+        lcd.cls();
+        First = 0;
+    }
+    
+    //Prints character after 3 ticks
+    if(printSignal == 3) {
+        printChar(Value);
+        printSignal = 0;
+        Value = 0;
+    }
+    
+    //Clears screen after 20 ticks
+    if(clearSignal == 20) {
+        lcd.cls();
+        clearSignal = 0;
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MorseCode.h	Wed Oct 21 18:06:05 2015 +0000
@@ -0,0 +1,1 @@
+void MorseCode(int tick);
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Wed Oct 21 18:06:05 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/TextLCD/#e4cb7ddee0d3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Oct 21 18:06:05 2015 +0000
@@ -0,0 +1,53 @@
+#include "mbed.h"
+#include "MorseCode.h"
+
+DigitalOut LED(LED1); // LED that blinks every .5 seconds
+PwmOut Speaker(p21); // Speaker
+Timer Time;
+AnalogIn photocell(p15); //CdS Powercell
+
+int main() {
+    int up = 0;
+    int read = 0;
+    Speaker.period(1.0/800.0);  //initializes speaker tone
+    Time.start();   //starts timer
+    int value = 0;
+    
+    while(1) {
+    
+        //Timer
+        if(Time.read_ms()%500<15) { 
+            up = !up;
+            read = 0;
+            if((Time.read_ms() - 1740000) > 0) {
+                Time.reset();
+            }
+            wait_ms(15);
+        }
+        
+        //LED
+        LED = (up)? 1 : 0;  //LED blinks every other .5 second
+        
+        //Reads in Morse Code  
+        if(Time.read_ms()%500 > 250 && read == 0) { // .25 Second Has Passed
+            read = 1;
+            if (photocell.read() < 0.5) {  
+                value = 0;      //if the light is not on
+            } else {
+                value = 1;      //if the light is on
+            }
+            MorseCode(value); //Translates the Morse code
+        }
+        
+        //Speaker
+        if(value) {
+            Speaker = 0.1;  //Plays tone if light is on
+            wait_ms(15);
+        }
+        else {
+            Speaker = 0.0; //Mutes tone if light is off
+            wait_ms(15);
+        }
+        
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Oct 21 18:06:05 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/34e6b704fe68
\ No newline at end of file