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:
- resolutedreamer
- Date:
- 2014-12-11
- Revision:
- 6:3fbe44c7c26a
- Parent:
- 5:112df51d4815
- Child:
- 7:c81c6968f013
File content as of revision 6:3fbe44c7c26a:
#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);
Ticker ticker;
char my_time[31];
int tick_count = 0;
void systick() {
if (tick_count % 10 == 0) {
redled = true;
}
else {
redled = false;
}
tick_count++;
}
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");
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
/*
//on hold for a moment
my_time[i] = pc.getc();
if (i == 29)
{
i = 0;
}
*/
}
}
