Craig Evans
/
1620_App_Board_LDR
LDR
Fork of 1620_App_Board_Temperature_Sensor by
Diff: main.cpp
- Revision:
- 2:1c669cb14c5b
- Parent:
- 1:b5c4ca3bf074
- Child:
- 3:ce5582846693
--- a/main.cpp Tue Feb 28 20:11:55 2017 +0000 +++ b/main.cpp Tue Feb 28 20:20:49 2017 +0000 @@ -1,6 +1,6 @@ /* ELEC1620 Application Board Example -TMP36 +LDR (c) Dr Craig A. Evans, University of Leeds, Feb 2017 @@ -12,8 +12,8 @@ // JP1 on board must be in 2-3 position N5110 lcd(p8,p9,p10,p11,p13,p21); -// Temperature sensor connected to ADC pin -AnalogIn tmp36(p16); +// LDR connected to ADC pin +AnalogIn ldr(p15); int main() { @@ -21,24 +21,25 @@ while(1) { - // read in the ADC value and convert to voltage - float voltage = 3.3f * tmp36.read(); + // clear the display at the start of every new frame + lcd.clear(); - // T = 100V - 50 - // convert voltage to temperature - float temperature = 100.0f*voltage - 50.0f; + // lcd is 84 pixels wide x 48 pixels high + + // x, y, width, height, outline + lcd.drawRect(12,20,60,8,0); - // we need an array of chars to store the message - char buffer[14]; // max screen witdth is 14 - // print message to buffer - sprintf(buffer,"T=%.2f C",temperature); - // print to screen (x pixel, line number) - lcd.printString(buffer,0,0); + float value = ldr.read(); // read in the LDR value in range 0.0 to 1.0 + + int width = int(value*60.0f); // convert to an int in the range 0.0 to 60.0 + + // draw a bar of the correct width + lcd.drawRect(12,20,width,8,1); // the 1 makes a black rectangle + // update the LCD lcd.refresh(); - // small delay between readings - wait(1.0); + wait(0.2); } }