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
main.cpp
- Committer:
- jhaugen
- Date:
- 2014-12-12
- Revision:
- 7:c81c6968f013
- Parent:
- 6:3fbe44c7c26a
- Child:
- 8:a44d03ecc942
File content as of revision 7:c81c6968f013:
#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);
Timer timer;
//initialize variables
Ticker ticker;
char t1_string[31];
char t4_string[31];
int t2;
int t3;
int i = 0;
bool pulse_value = false;
float let_there_be_light = 0.0;
float my_analog_value = 0.0;
Convert lcd;
bool read_complete = false;
int tick_count = 0;
void systick() {
if (tick_count % 10 == 0) {
redled = true;
// 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);
}
else if (tick_count % 10 == 1) {
redled = false;
// 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);
}
else if (tick_count % 30 == 0) {
//pc.printf("\r\n\r\n GOT A STRING: %s\r\n\r\n", t1_string);
}
tick_count++;
}
int main()
{
timer.start();
//initialize hardware
ticker.attach_us(&systick, 100000);
pc.baud(115200);
t1_string[30] = '\0';
//we start the program
pc.printf("Hello World!\n");
while (true)
{
char c = pc.getc();
t2 = timer.read_us();
// make sure we've gotten an 's', which we are using as
// the sync message. If we get an 's' then t2 is correct.
if (c != 's') {
continue;
}
while (c != '\n') {
if (i == 30) {
break;
}
t1_string[i] = c;
c = pc.getc();
i++;
}
t1_string[i] = '\0';
i = 0;
char display_time[5];
display_time[0] = t1_string[4];
display_time[1] = t1_string[5];
display_time[2] = t1_string[7];
display_time[3] = t1_string[8];
display_time[4] = '\0';
int display_time_int = atoi(display_time);
lcd.display(display_time_int);
//lcd.display(t1_string[7]);
read_complete = true;
t3 = timer.read_us();
// sending the delay_req message at time t3
pc.putc('r');
// get the t4 packet
while (c != '\n') {
if (i == 30) {
break;
}
t4_string[i] = c;
c = pc.getc();
i++;
}
t4_string[i] = '\0';
i = 0;
}
}
