Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 #include "MorseCode.h" 00003 00004 DigitalOut LED(LED1); // LED that blinks every .5 seconds 00005 PwmOut Speaker(p21); // Speaker 00006 Timer Time; 00007 AnalogIn photocell(p15); //CdS Powercell 00008 00009 int main() { 00010 int up = 0; 00011 int read = 0; 00012 Speaker.period(1.0/800.0); //initializes speaker tone 00013 Time.start(); //starts timer 00014 int value = 0; 00015 00016 while(1) { 00017 00018 //Timer 00019 if(Time.read_ms()%500<15) { 00020 up = !up; 00021 read = 0; 00022 if((Time.read_ms() - 1740000) > 0) { 00023 Time.reset(); 00024 } 00025 wait_ms(15); 00026 } 00027 00028 //LED 00029 LED = (up)? 1 : 0; //LED blinks every other .5 second 00030 00031 //Reads in Morse Code 00032 if(Time.read_ms()%500 > 250 && read == 0) { // .25 Second Has Passed 00033 read = 1; 00034 if (photocell.read() < 0.5) { 00035 value = 0; //if the light is not on 00036 } else { 00037 value = 1; //if the light is on 00038 } 00039 MorseCode(value); //Translates the Morse code 00040 } 00041 00042 //Speaker 00043 if(value) { 00044 Speaker = 0.1; //Plays tone if light is on 00045 wait_ms(15); 00046 } 00047 else { 00048 Speaker = 0.0; //Mutes tone if light is off 00049 wait_ms(15); 00050 } 00051 00052 } 00053 }
Generated on Mon Jul 18 2022 04:15:36 by
1.7.2