//#MASTER I2C #include #include #include #include #include Servo myservo; // create servo object to control a servo // twelve servo objects can be created on most boards int pos = 0; // variable to store the servo position int buz = 0; // variable to store the servo position #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 32 // OLED display height, in pixels #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) #define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); #define servoPin D3 #define buzzerPin D6 void setup() { myservo.attach(servoPin); // attaches the servo on pin D3 to the servo object // initialise les broches du Buzzer pinMode(buzzerPin, OUTPUT); Wire.begin(); // join i2c bus (address optional for master) Serial.begin(9600); // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1306 allocation failed")); for (;;); // Don't proceed, loop forever } display.display(); delay(1000); // Pause for 2 seconds // Clear the buffer display.clearDisplay(); } void loop() { byte temperature; Wire.requestFrom(2, 1); // Request temperature data from slave at 2 if (Wire.available()) { temperature = Wire.read(); // Read temperature data from slave Serial.print("Temperature from Slave: "); Serial.print(temperature); Serial.println(" C"); } display.clearDisplay(); display.setTextSize(2); // Draw 2X-scale text display.setTextColor(SSD1306_WHITE); display.setCursor(0, 0); buz = map(temperature, 25, 35, 100, 1000); pos = map(temperature, 25, 35, 0, 180); myservo.write(pos); // tell servo to go to mapped position in variable 'pos' delay(15); // display.print(F("Hr: ")); // display.print(h); // display.println(F("%")); display.print(F("T: ")); display.print(temperature); display.println(F("C")); display.display(); delay (500); display.clearDisplay(); Serial.print(F("buz: ")); Serial.println(buz); Serial.print(F("Angle: ")); Serial.println(pos); // Serial.print(F("Humidity: ")); // Serial.print(h); // Serial.print(F("% Temperature: ")); // Serial.print(t); // Serial.println(F("°C ")); alarm(); } void alarm() { tone(buzzerPin, buz); // allume le buzzer actif arduino delay(250); noTone(buzzerPin); // désactiver le buzzer actif arduino delay(100); }