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: N5110WN PowerControl SRF02 mbed
Diff: main.cpp
- Revision:
- 4:2e9aa626a02c
- Parent:
- 3:00933efbe463
- Child:
- 5:f9b97f057836
--- a/main.cpp Sat Mar 21 19:14:04 2015 +0000
+++ b/main.cpp Wed Apr 08 00:46:27 2015 +0000
@@ -5,13 +5,11 @@
*/
#include "main.h"
-
-
int main()
{
pc.baud(9600); //sets baud rate
timer.attach(&timerExpired,0.5);
- LogTog.rise(&logButtonPressed);
+ LogTog.rise(&logToggle);
UnitTog.rise(&unitToggle);
VisTog.rise(&visToggle);
pc.attach(&serialISR); // attach serial ISR
@@ -34,9 +32,9 @@
wait(2);
lcd.clear();
while(1) {
- BLED=BLEDLevel.read(); //sets the brightness
+
if(timerFlag) {
-
+ BLED=BLEDLevel.read(); //sets the brightness
timerFlag = 0; //resets flag
time_t seconds = time(NULL); // get current time
// format time into a string (time and date)
@@ -59,6 +57,9 @@
else if(visual==2) {
LCDVis2();
}
+ else if(visual==3) {
+ LCDVis3();
+ }
else{ error(2);}
}
@@ -140,7 +141,7 @@
}
}
-void logButtonPressed()
+void logToggle()
{
logButtonFlag = !logButtonFlag; //flips the flag
if(logButtonFlag) {
@@ -160,10 +161,10 @@
// if the file doesn't exist it is created, if it exists, data is appended to the end
fprintf(fp," %s , %.2f\n ",data,data1); // print string to file
fclose(fp); // close file
- pc.printf("Data Logged\n\r");
+ pc.printf("Data Logged\n");
LLED=1; //keeps the led on if it is logging
} else {
- pc.printf("WARNING : Unlogged Data\n\r");
+ pc.printf("WARNING : Unlogged Data\n");
LLED=0;
}
}
@@ -217,12 +218,9 @@
{
lcd.clear();
int I = distance*0.337; //and then multiplies the current distance by that value as (84/249) =0.337...
- pc.printf("bar width - %d pixels \n",I);
- for(int j=0; j<48; j++) {
- for(int i=0; i<I; i++) {
- lcd.setPixel(i,j);
- }
- }
+ pc.printf("bar width - %d pixels \n",I);
+ lcd.printString("%s",0,0);
+ lcd.drawRect(0,18,I,12,1);
lcd.refresh();
}
@@ -230,23 +228,97 @@
{
lcd.clear();
int J = distance*0.19; //and then multiplies the current distance by that value as (48/249) = 0.19..
- pc.printf("bar height - %d pixels \n",J);
- for(int i=0; i<84; i++) {
- for(int j=0; j<J; j++) {
- lcd.setPixel(i,48-j); //using 48-j here makes the bar fill from the bottom rather than from the top as pixel(0,0) is the top left corner
-
- }
- }
+ if(J>=48){J=48;}
+ pc.printf("bar height - %d pixels \n",J);
+ lcd.drawRect(27,48-J,30,48,1);
lcd.refresh();
}
void LCDVis2(){
- for(int i=0; i<84; i++) {
- for(int j=0; j<48; j++) {
- lcd.setPixel(i,j);
- }
+ lcd.clear();
+ car();
+ int I = distance*0.277; //and then multiplies the current distance by that value as (69/249) =0.277...
+ if(I>=84){I=84;}
+ pc.printf("bar width - %d pixels \n",I);
+ lcd.drawRect(I+15,9,69,30,1);
+ lcd.refresh();
+}
+void LCDVis3(){
+ lcd.clear();
+ int Dist=distance;
+ if(state==0){
+ lcd.printString("CM",54,3);
+ }
+ if(state==1){
+ decimal();
+ lcd.printString("M",54,3);
+ }
+ if(state==2){
+ number0(57);
+ lcd.printString("MM",73,3);
+ }
+ int S=Dist %10;
+ pc.printf("singles - %d \n",S);
+ if(S==0){
+ number0(38);
+ }
+ if(S==1){
+ number1(38);
+ }
+ if(S==2){
+ number2(38);
+ }
+ if(S==3){
+ number3(38);
+ }
+ if(S==4){
+ number4(38);
+ }
+ if(S==5){
+ number5(38);
}
- lcd.refresh();
+ if(S==6){
+ number6(38);
+ }
+ if(S==7){
+ number7(38);
+ }
+ if(S==8){
+ number8(38);
+ }
+ if(S==9){
+ number9(38);
+ }
+
+ int T=Dist/10 %10;
+ pc.printf("tens - %d \n",t);
+ if(T==0){
+ number0(19);
+ }
+ int H=Dist/100 %10;
+ pc.printf("Hundreds - %d \n",H);
+ if(H==0){
+ number0(0);
+ }
+}
+
+
+
+
+
+
+void car(){
+ lcd.setPixel(4,19);lcd.setPixel(5,19);lcd.setPixel(6,19); lcd.setPixel(10,19);lcd.setPixel(11,19);lcd.setPixel(12,19);
+ lcd.setPixel(4,20);lcd.setPixel(5,20);lcd.setPixel(6,20); lcd.setPixel(10,20);lcd.setPixel(11,20);lcd.setPixel(12,20);
+ lcd.setPixel(1,21);lcd.setPixel(2,21);lcd.setPixel(3,21);lcd.setPixel(4,21);lcd.setPixel(5,21);lcd.setPixel(6,21);lcd.setPixel(7,21);lcd.setPixel(8,21);lcd.setPixel(9,21);lcd.setPixel(10,21);lcd.setPixel(11,21);lcd.setPixel(12,21);lcd.setPixel(13,21);
+ lcd.setPixel(0,22);lcd.setPixel(1,22);lcd.setPixel(2,22);lcd.setPixel(3,22);lcd.setPixel(4,22); lcd.setPixel(6,22);lcd.setPixel(7,22);lcd.setPixel(8,22);lcd.setPixel(9,22);lcd.setPixel(10,22); lcd.setPixel(12,22);lcd.setPixel(13,22);
+ lcd.setPixel(0,23);lcd.setPixel(1,23);lcd.setPixel(2,23);lcd.setPixel(3,23); lcd.setPixel(6,23);lcd.setPixel(7,23);lcd.setPixel(8,23);lcd.setPixel(9,23);lcd.setPixel(10,23); lcd.setPixel(12,23);lcd.setPixel(13,23);
+ lcd.setPixel(0,24);lcd.setPixel(1,24);lcd.setPixel(2,24);lcd.setPixel(3,24); lcd.setPixel(6,24);lcd.setPixel(7,24);lcd.setPixel(8,24);lcd.setPixel(9,24);lcd.setPixel(10,24); lcd.setPixel(12,24);lcd.setPixel(13,24);
+ lcd.setPixel(0,25);lcd.setPixel(1,25);lcd.setPixel(2,25);lcd.setPixel(3,25); lcd.setPixel(6,25);lcd.setPixel(7,25);lcd.setPixel(8,25);lcd.setPixel(9,25);lcd.setPixel(10,25); lcd.setPixel(12,25);lcd.setPixel(13,25);
+ lcd.setPixel(0,26);lcd.setPixel(1,26);lcd.setPixel(2,26);lcd.setPixel(3,26);lcd.setPixel(4,26); lcd.setPixel(6,26);lcd.setPixel(7,26);lcd.setPixel(8,26);lcd.setPixel(9,26);lcd.setPixel(10,26); lcd.setPixel(12,26);lcd.setPixel(13,26);
+ lcd.setPixel(1,27);lcd.setPixel(2,27);lcd.setPixel(3,27);lcd.setPixel(4,27);lcd.setPixel(5,27);lcd.setPixel(6,27);lcd.setPixel(7,27);lcd.setPixel(8,27);lcd.setPixel(9,27);lcd.setPixel(10,27);lcd.setPixel(11,27);lcd.setPixel(12,27);lcd.setPixel(13,27);
+ lcd.setPixel(4,28);lcd.setPixel(5,28);lcd.setPixel(6,28); lcd.setPixel(10,28);lcd.setPixel(11,28);lcd.setPixel(12,28);
+ lcd.setPixel(4,29);lcd.setPixel(5,29);lcd.setPixel(6,29); lcd.setPixel(10,29);lcd.setPixel(11,29);lcd.setPixel(12,29);
}
void visToggle()
@@ -261,6 +333,9 @@
pc.printf("----Up to Down----\n\r");
}
if(visual==2) {
- pc.printf("----Other----\n\r");
+ pc.printf("----Car & Wall----\n\r");
+ }
+ if(visual==3) {
+ pc.printf("----Numbers----\n\r");
}
}
\ No newline at end of file