#include "SSD1306Ascii.h"
#include "SSD1306AsciiAvrI2c.h"
#define I2C_ADDRESS 0x3C
#define RST_PIN -1
SSD1306AsciiAvrI2c oled;
int potar, light, buttonState1, buttonState2, compteur1, compteur2;
bool buzz = 1;
void setup() {
Serial.begin(9600);
oled.begin(&Adafruit128x64, I2C_ADDRESS, RST_PIN);
oled.setFont(Adafruit5x7);
oled.clear();
oled.set1X();
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(4, INPUT);
pinMode(5, INPUT);
}
void loop() {
potar = map(analogRead(A0), 0, 1023, 0, 100);
light = map(1023 - analogRead(A1), 0, 1023, 0, 100);
if (potar == 0) {
compteur1 = 0; compteur2 = 0; buzz = 1;//si on met le potar à zéro on active le son du buzzer
}
if (compteur1 == 10 and compteur2 == 10) {
buzz = 0;//si la valeur des 2 boutons est 10 on coupe le buzzer
}
oled.clear(40, 70, 0, 64);//efface qu'une partie de l ecran
//oled.clear();
oled.print("\nPOTAR: ");
oled.print( potar);
oled.println( "");
oled.print("\nLIGHT: ");
oled.print(light);
oled.println( "");
oled.print("\n B1: ");
oled.print(compteur1);
oled.println( "");
oled.print("\n B2: ");
oled.print(compteur2);
buttonState1 = digitalRead(4);
buttonState2 = digitalRead(5);
if (buttonState1 == LOW) {
digitalWrite(11, HIGH);
if (buzz == 1) {
tone(10, analogRead(A0) * 2);
}
compteur1 += 1;
}
else {
digitalWrite(11, LOW);
}
if (buttonState2 == LOW) {
digitalWrite(12, HIGH);
if (buzz == 1) {
tone(10, analogRead(A0) * 4);
}
compteur2 += 1;
}
else {
digitalWrite(12, LOW);
}
if (buttonState2 == HIGH and buttonState1 == HIGH) {
noTone(10);
}
delay(100);
}