Morse Code Machine

Dependencies:   TextLCD mbed

Fork of TextLCD_HelloWorld by Simon Ford

Committer:
Jgreub
Date:
Fri Mar 01 00:34:34 2013 +0000
Revision:
3:3f863fcfd172
Parent:
2:ad0b044d0a10
Morse Code Machine

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jgreub 3:3f863fcfd172 1 // Morse Code Machine February 27, 2013
simon 1:7418a52375a0 2
simon 0:334327d1a416 3 #include "mbed.h"
Jgreub 3:3f863fcfd172 4 #include "MorseCode.h"
simon 0:334327d1a416 5
Jgreub 3:3f863fcfd172 6 //Need to Setup LCD Screen as TextLCD lcd(p15, p16, p17, p18, p19, p20) - Is included in MorseCode.cpp
Jgreub 3:3f863fcfd172 7 DigitalIn Button(p8); // Button for User to Input Morse Code
Jgreub 3:3f863fcfd172 8 DigitalOut LED(LED1); // LED to Indicate Time (every 1 seconds)
Jgreub 3:3f863fcfd172 9 PwmOut Speaker(p21); // Speaker to play noise when button pushed
Jgreub 3:3f863fcfd172 10 Timer Time; // Keeps track of time
simon 0:334327d1a416 11
simon 0:334327d1a416 12 int main() {
Jgreub 3:3f863fcfd172 13 // Setup
Jgreub 3:3f863fcfd172 14 int up = 0;
Jgreub 3:3f863fcfd172 15 int read = 0;
Jgreub 3:3f863fcfd172 16 Button.mode(PullUp);
Jgreub 3:3f863fcfd172 17 Speaker.period(1.0/800.0);
Jgreub 3:3f863fcfd172 18 Time.start();
Jgreub 3:3f863fcfd172 19
Jgreub 3:3f863fcfd172 20 //Start
Jgreub 3:3f863fcfd172 21 while(1) {
Jgreub 3:3f863fcfd172 22
Jgreub 3:3f863fcfd172 23 //Timer For User Comfort
Jgreub 3:3f863fcfd172 24 if(Time.read_ms()%1000<15) {
Jgreub 3:3f863fcfd172 25 up = !up;
Jgreub 3:3f863fcfd172 26 read = 0; // Reset for Next Second
Jgreub 3:3f863fcfd172 27 if((Time.read_ms() - 1740000) > 0) {
Jgreub 3:3f863fcfd172 28 Time.reset(); // Reset if more than 29 minutes.
Jgreub 3:3f863fcfd172 29 }
Jgreub 3:3f863fcfd172 30 wait_ms(15);
Jgreub 3:3f863fcfd172 31 }
Jgreub 3:3f863fcfd172 32
Jgreub 3:3f863fcfd172 33 // LED Ticker
Jgreub 3:3f863fcfd172 34 LED = (up)? 1 : 0;
Jgreub 3:3f863fcfd172 35
Jgreub 3:3f863fcfd172 36 // Audio
Jgreub 3:3f863fcfd172 37 if(!Button) {
Jgreub 3:3f863fcfd172 38 Speaker = 0.25; // Volume
Jgreub 3:3f863fcfd172 39 wait_ms(15);
Jgreub 3:3f863fcfd172 40 }
Jgreub 3:3f863fcfd172 41 else {
Jgreub 3:3f863fcfd172 42 Speaker = 0.0; //Mute
Jgreub 3:3f863fcfd172 43 wait_ms(15);
Jgreub 3:3f863fcfd172 44 }
Jgreub 3:3f863fcfd172 45
Jgreub 3:3f863fcfd172 46 // Do Morse Code
Jgreub 3:3f863fcfd172 47 if(Time.read_ms()%1000 > 500 && read == 0) { // Half a Second Has Passed
Jgreub 3:3f863fcfd172 48 read = 1;
Jgreub 3:3f863fcfd172 49 MorseCode(!Button); // Read Button Value
Jgreub 3:3f863fcfd172 50 }
Jgreub 3:3f863fcfd172 51
Jgreub 3:3f863fcfd172 52 }// End While
simon 0:334327d1a416 53 }