Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
|
wiki:divers:preparation_are_2019 [2019/01/09 16:05] Christian Simon Essai du capteur réflectif IR Vishay V69 CNY70 sur un M5 Stack. |
wiki:divers:preparation_are_2019 [2019/01/09 16:14] (Version actuelle) Christian Simon |
||
|---|---|---|---|
| Ligne 11: | Ligne 11: | ||
| Bref. | Bref. | ||
| + | |||
| + | On utilise deux résistances : | ||
| + | * protection de la LED IR : 100 Ω | ||
| + | * émetteur phototransistor : 56 kΩ | ||
| + | |||
| + | Les mesures obtenues par AnalogRead vont de 0 (capteur pointé vers le ciel) à 4095 (capteur au contact). | ||
| + | |||
| + | Le code : | ||
| + | < | ||
| + | #include < | ||
| + | |||
| + | |||
| + | unsigned long temps; | ||
| + | char affichage[12]; | ||
| + | int sensorPin = 2; | ||
| + | // the setup routine runs once when M5Stack starts up | ||
| + | void setup() { | ||
| + | | ||
| + | // initialize the M5Stack object | ||
| + | M5.begin(); | ||
| + | pinMode(sensorPin, | ||
| + | |||
| + | // Lcd display | ||
| + | |||
| + | M5.Lcd.fillScreen(BLACK); | ||
| + | |||
| + | // text print | ||
| + | M5.Lcd.fillScreen(BLACK); | ||
| + | M5.Lcd.setCursor(10, | ||
| + | M5.Lcd.setTextColor(WHITE); | ||
| + | M5.Lcd.setTextSize(1); | ||
| + | M5.Lcd.printf(" | ||
| + | |||
| + | |||
| + | } | ||
| + | |||
| + | // the loop routine runs over and over again forever | ||
| + | void loop(){ | ||
| + | int level; | ||
| + | | ||
| + | temps = millis(); | ||
| + | ltoa(temps, | ||
| + | level = analogRead(sensorPin); | ||
| + | M5.Lcd.setCursor(10, | ||
| + | M5.Lcd.printf(affichage); | ||
| + | M5.Lcd.setCursor(10, | ||
| + | M5.Lcd.printf(" | ||
| + | delay(1000); | ||
| + | M5.Lcd.fillScreen(BLACK); | ||
| + | M5.update(); | ||
| + | }</ | ||