Principe
La valeur du capteur de lumière est affiche sur le LCD
Materiel
- Arduino UNO R3
- Afficheur I2C Batron BTHQ 21605AV-02 (DataSheet_afficheur_I2C)
- Capteur lumière phidget 1127 (Light_sensor_module_doc)
Cablage
Code source
#include <Wire.h> #include <LCDI2C.h> const int PIN_INPUT_SENSOR = A0; int currentValue = 0; //I2C display adress (found by I2C scanner #define LCDI2C_ADDRESS 0x3B //I2C display setup : Number of lines, char and i2c address of the display LCDI2C lcd = LCDI2C(2,16,LCDI2C_ADDRESS); void setup() { //Start I2C bus Wire.begin(); //Init the display, clears the display lcd.init(); lcd.printstr("Starting..."); } void updateDisplayedValue() { lcd.clear(); lcd.printstr("Value"); lcd.setCursor(1,0); String atexte=String(currentValue); char charBuf[50]; atexte.toCharArray(charBuf, 50); lcd.printstr(charBuf); } void loop() { //Read sensor value currentValue = analogRead(PIN_INPUT_SENSOR)*100; //update the display with new value updateDisplayedValue(); //wait a little delay(150); }
librairies
- LCDI2C : http://www.arduino.cc/playground/Code/LCDi2c
- Wire : http://www.arduino.cc/en/Reference/Wire
- Arduino beta 23