1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| #include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "MCP_ADC.h"
MCP3008 mcp1; // use HWSPI
LiquidCrystal_I2C lcd(0x38, 16, 2);
String text = "La tension sur le channel 0 est de : ";
unsigned long long prevMillis = 0; //variable sur 32 bits
unsigned long long tempo = 200;//fixe une tempo de 200 ms
bool State = LOW;
void setup()
{
Serial.begin(9600);
mcp1.begin(10);
lcd.init();
lcd.cursor_on();
// lcd.blink_on();
lcd.backlight();
lcd.setCursor(2, 0);
lcd.home();
}
void loop()
{
float val = mcp1.analogRead(0);
val = val * 5;
val = val / 1000;
if ((millis() - prevMillis) > tempo) {
State = ! State;
if (!State)
{
lcd.print("<<<");
lcd.print(text);
lcd.print(val);
lcd.print(" volts");
lcd.print(">>>");
for (int a = 0; a < 55; a++)//permet de faire défiler le texte de droite à gauche
{
lcd.scrollDisplayLeft();
}
}
prevMillis = millis();
}
} |
Partager