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: MODSERIALhacked Convert SLCD mbed-src
Diff: main.cpp
- Revision:
- 6:3fbe44c7c26a
- Parent:
- 5:112df51d4815
- Child:
- 7:c81c6968f013
diff -r 112df51d4815 -r 3fbe44c7c26a main.cpp
--- a/main.cpp Thu Dec 11 03:41:36 2014 +0000
+++ b/main.cpp Thu Dec 11 04:07:33 2014 +0000
@@ -1,14 +1,16 @@
#include "mbed.h"
#include "convert.h"
+Serial pc(USBTX, USBRX);
+AnalogIn my_light_sensor(PTE22);
+AnalogIn my_analog_pin(PTB0);
// false == on; true == off for the leds
DigitalOut myled(LED_GREEN);
DigitalOut redled(LED_RED);
-Serial pc(USBTX, USBRX);
-AnalogIn my_light_sensor(PTE22);
Ticker ticker;
+char my_time[31];
int tick_count = 0;
void systick() {
@@ -22,40 +24,67 @@
}
int main()
-{
+{
+ //initialize hardware
ticker.attach_us(&systick, 100000);
pc.baud(115200);
+ Convert lcd;
+
+ //initialize variables
int i = 0;
bool pulse_value = false;
+ float let_there_be_light = 0.0;
+ float my_analog_value = 0.0;
+ my_time[30] = '\0';
+
+ //we start the program
pc.printf("Hello World!\n");
- Convert lcd;
-
- while (true) {
-
- float let_there_be_light;
-
- // set the pulse high for 100ms
- pulse_value = true;
- myled = pulse_value; // toggle a led
- let_there_be_light = my_light_sensor.read();
- pc.printf("%f \r\n", let_there_be_light);
- lcd.display(1);
- wait_ms(100.0f);
-
- // set it low again for the remainder of the second
- pulse_value = false;
- myled = pulse_value; // toggle a led
- let_there_be_light = my_light_sensor.read();
- pc.printf("%f \r\n", let_there_be_light);
- lcd.display(0);
- wait_ms(900.0f);
-
+
+ while (true)
+ {
+ // Beginning of a second
+ // set the pulse high for 100ms, .1 s
+ // toggle a led
+ pulse_value = true;
+ myled = pulse_value;
+
+ // get data from the (2) light sensor (3) analog pin
+ let_there_be_light = my_light_sensor.read();
+ my_analog_value = my_analog_pin.read();
+
+ // print the analog values to uart
+ pc.printf("%f,%f\r\n", let_there_be_light, my_analog_value);
+
+ // display 1
+ lcd.display(1);
+ wait_ms(100.0f);
+
+ // set the pulse low for 900 ms, .9 s
+ // toggle a led
+ pulse_value = false;
+ myled = pulse_value; // toggle a led
+
+ // get data from the (2) light sensor (3) analog pin
+ let_there_be_light = my_light_sensor.read();
+ my_analog_value = my_analog_pin.read();
+
+ // print the analog values to uart
+ pc.printf("%f,%f\r\n", let_there_be_light, my_analog_value);
+
+ // display 0
+ lcd.display(0);
+ wait_ms(900.0f);
+
+ // End of a second
/*
- pc.printf("%d \n", i); // print the value of variable i
- i++; // increment the variable
- myled = pulsevalue; // toggle a led
+ //on hold for a moment
+ my_time[i] = pc.getc();
+ if (i == 29)
+ {
+ i = 0;
+ }
*/
}
}
