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.
Dependencies: 4DGL-uLCD-SE mbed
main.cpp
00001 #include "mbed.h" 00002 #include <vector> 00003 #include <string> 00004 #include <algorithm> 00005 #include <iostream> 00006 #include <iomanip> 00007 #include "uLCD_4DGL.h" 00008 #include "Speaker.h" 00009 00010 00011 //puzzle with hint 00012 std::string puzz[11][2] = { 00013 {"SAYING", "TO HELL WITH GEORGIA"}, 00014 {"HOME SWEET HOME", "VAN LEER"}, 00015 {"1913", "BOBBY DODD STADIUM"}, 00016 {"NAND", "DIGITAL DESIGN"}, 00017 {"RULES 1&2", "KIRCHHOFF'S LAWS"}, 00018 {"HARMONICS", "FOURIER SERIES"}, 00019 {"VR", "TRANSFORMER"}, 00020 {"J'HABITE", "GT LORRAINE"}, 00021 {"GRADUATION", "DEGREE WORKS"}, 00022 {"PAIN", "STUDENT LOANS"}, 00023 {"EXPERIENCE", "INTERSHIP"} 00024 }; 00025 00026 00027 00028 Serial pc(USBTX,USBRX); //talk to pc 00029 DigitalOut myled(LED1); //led for debugging 00030 DigitalIn pb(p8); //button 00031 uLCD_4DGL uLCD(p9,p10,p11); // ulcd serial tx, serial rx, reset pin; 00032 PwmOut speaker(p21); //speaker 00033 00034 00035 00036 int main() 00037 { 00038 00039 uLCD.cls(); // clear ulcd 00040 uLCD.baudrate(9600); //change baud rate 00041 int x=4; 00042 int x2=6; 00043 int color=GREEN; //rectangle color iss green 00044 int i=0; 00045 double power; 00046 int val; 00047 00048 pb.mode(PullUp); //internal pullup for button 00049 uLCD.color(RED); //make text red 00050 uLCD.locate(1,6); 00051 uLCD.printf("Power");//label 00052 uLCD.locate(1,9); 00053 uLCD.printf("Low");//label 00054 uLCD.locate(14,9); 00055 uLCD.printf("High");//label 00056 uLCD.rectangle(3, 59, 125, 69,RED ); //make rectangle outline red 00057 int r; 00058 int end=0; 00059 r=rand()%11; //to choose a random puzzle 00060 while(1) { 00061 00062 //make power bar that goes back and forth 00063 uLCD.filled_rectangle(x,60, x2,68,color); 00064 00065 if (x2<124 && i==0) { 00066 x=x+2; 00067 x2=x2+2; 00068 } else if (x2>4 && i==1) { 00069 x=x-2; 00070 x2=x2-2; 00071 } 00072 if(x2==124) { 00073 i=1; 00074 color=BLACK; 00075 } else if(x2==4) { 00076 i=0; 00077 x=4; 00078 x2=6; 00079 color=GREEN; 00080 } 00081 00082 //when button is pushed 00083 if (pb==0) { 00084 end=1; 00085 wait(.5); 00086 } 00087 //if data sent over comport 00088 if(pc.readable()) { 00089 char g= pc.getc(); 00090 uLCD.locate(4,1); 00091 00092 uLCD.locate(6,1); 00093 //return puzzle string 00094 if (g=='v') { 00095 for (int y=0; y<puzz[r][1].size(); y++) { 00096 pc.putc(puzz[r][1][y]); //return puzzle 00097 } 00098 00099 00100 } 00101 //return puzzle's hint 00102 if (g=='k') { 00103 for (int y=0; y<puzz[r][0].size(); y++) { 00104 pc.putc(puzz[r][0][y]); //return hint 00105 00106 } 00107 00108 r=rand()%11; //store new random number 00109 g=' '; 00110 } 00111 //if player changed make noise 00112 if(g=='b') { 00113 speaker.period(1.0/100.0); // 100hz period 00114 speaker =0.3; //3% duty cycle - max volume 00115 wait(.2); 00116 speaker=0; 00117 wait(.05); 00118 speaker.period(1.0/100.0); // 100hz period 00119 speaker =0.3; //30% duty cycle - max volume 00120 wait(.2); 00121 00122 speaker=0; 00123 00124 g=' '; 00125 } 00126 00127 00128 } 00129 //if button pushed send power value to pc using rectangle coord. 00130 if(end==1) { 00131 00132 power=((x2-double(6))/double(118)); //decimal value 00133 val=power*100; //power out of 100 00134 uLCD.locate(1,1); 00135 if(val!=NULL) { 00136 pc.putc(val); //print to pc 00137 00138 } 00139 00140 end=0; 00141 } 00142 00143 } 00144 } 00145
Generated on Wed Aug 17 2022 00:31:10 by
1.7.2