start:arduino:esp32:smarthome
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
start:arduino:esp32:smarthome [2025/08/29 14:41] – [Test Servo Porte Avant] admin | start:arduino:esp32:smarthome [2025/08/29 21:36] (Version actuelle) – [DemoFablab] admin | ||
---|---|---|---|
Ligne 283: | Ligne 283: | ||
<code c Test-Servo-Fenetre_Test_Capt-Humidite.ino> | <code c Test-Servo-Fenetre_Test_Capt-Humidite.ino> | ||
- | #include <ESP32_Servo.h> | + | #include <ESP32Servo.h> |
Servo myservo; | Servo myservo; | ||
#define servoPin 5 | #define servoPin 5 | ||
Ligne 981: | Ligne 981: | ||
} // longPressStop2 | } // longPressStop2 | ||
</ | </ | ||
+ | ==== DemoFablab ==== | ||
+ | <code c demofablab.ino> | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include " | ||
+ | |||
+ | //#include < | ||
+ | #define fanPin1 19 | ||
+ | #define fanPin2 18 | ||
+ | #define led_y 12 //Define the yellow led pin to 12 | ||
+ | #define btnPin 16 | ||
+ | #define servoPinF 5 | ||
+ | #define waterPin 34 | ||
+ | #define LED_PIN | ||
+ | #define LED_COUNT 4 | ||
+ | |||
+ | xht11 xht(17); | ||
+ | unsigned char dht[4] = {0, 0, 0, 0};//Only the first 32 bits of data are received, not the parity bits | ||
+ | #ifdef __AVR__ | ||
+ | # | ||
+ | #endif | ||
+ | // Which pin on the Arduino is connected to the NeoPixels? | ||
+ | // On a Trinket or Gemma we suggest changing this to 1: | ||
+ | |||
+ | // How many NeoPixels are attached to the Arduino? | ||
+ | |||
+ | // Declare our NeoPixel strip object: | ||
+ | Adafruit_NeoPixel strip(LED_COUNT, | ||
+ | LiquidCrystal_I2C mylcd(0x27, | ||
+ | |||
+ | Servo myservoP; | ||
+ | Servo myservoF; | ||
+ | |||
+ | |||
+ | int pos = 0; // variable to store the servo position | ||
+ | int servoPinP = 13; | ||
+ | boolean btnFlag = 0; | ||
+ | String password = ""; | ||
+ | |||
+ | /*#include " | ||
+ | // IIC pins default to GPIO21 and GPIO22 of ESP32 | ||
+ | // 0x28 is the i2c address of SDA, if doesn' | ||
+ | MFRC522_I2C mfrc522(0x28); | ||
+ | |||
+ | void setup() { | ||
+ | // These lines are specifically to support the Adafruit Trinket 5V 16 MHz. | ||
+ | // Any other board, you can remove this part (but no harm leaving it): | ||
+ | #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000) | ||
+ | clock_prescale_set(clock_div_1); | ||
+ | #endif | ||
+ | // END of Trinket-specific code. | ||
+ | Serial.begin(115200); | ||
+ | Wire.begin(); | ||
+ | | ||
+ | / | ||
+ | ShowReaderDetails(); | ||
+ | Serial.println(F(" | ||
+ | pinMode(btnPin, | ||
+ | mylcd.setCursor(0, | ||
+ | mylcd.print(" | ||
+ | | ||
+ | strip.begin(); | ||
+ | strip.show(); | ||
+ | strip.setBrightness(50); | ||
+ | |||
+ | myservoP.attach(servoPinP); | ||
+ | |||
+ | pinMode(waterPin, | ||
+ | myservoF.attach(servoPinF, | ||
+ | myservoF.write(140); | ||
+ | delay(200); | ||
+ | |||
+ | pinMode(fanPin1, | ||
+ | pinMode(fanPin2, | ||
+ | |||
+ | mylcd.init(); | ||
+ | mylcd.backlight(); | ||
+ | |||
+ | pinMode(led_y, | ||
+ | } | ||
+ | |||
+ | |||
+ | // loop() function -- runs repeatedly as long as board is on --------------- | ||
+ | |||
+ | void loop() { | ||
+ | ledON(); | ||
+ | affiche(); | ||
+ | servo_porte(); | ||
+ | ledOFF(); | ||
+ | capt_temp(); | ||
+ | ventilateur001(); | ||
+ | ledON(); | ||
+ | affiche(); | ||
+ | LED_RVB() ; | ||
+ | capt_temp(); | ||
+ | ledOFF(); | ||
+ | affichefenetre(); | ||
+ | fenetre(); | ||
+ | affiche(); | ||
+ | } | ||
+ | |||
+ | |||
+ | // Some functions of our own for creating animated effects ----------------- | ||
+ | |||
+ | // Fill strip pixels one after another with a color. Strip is NOT cleared | ||
+ | // first; anything there will be covered pixel by pixel. Pass in color | ||
+ | // (as a single ' | ||
+ | // strip.Color(red, | ||
+ | // and a delay time (in milliseconds) between pixels. | ||
+ | void colorWipe(uint32_t color, int wait) { | ||
+ | for(int i=0; i< | ||
+ | strip.setPixelColor(i, | ||
+ | strip.show(); | ||
+ | delay(wait); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // Theater-marquee-style chasing lights. Pass in a color (32-bit value, | ||
+ | // a la strip.Color(r, | ||
+ | // between frames. | ||
+ | void theaterChase(uint32_t color, int wait) { | ||
+ | for(int a=0; a<10; a++) { // Repeat 10 times... | ||
+ | for(int b=0; b<3; b++) { // ' | ||
+ | strip.clear(); | ||
+ | // ' | ||
+ | for(int c=b; c< | ||
+ | strip.setPixelColor(c, | ||
+ | } | ||
+ | strip.show(); | ||
+ | delay(wait); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // Rainbow cycle along whole strip. Pass delay time (in ms) between frames. | ||
+ | void rainbow(int wait) { | ||
+ | // Hue of first pixel runs 5 complete loops through the color wheel. | ||
+ | // Color wheel has a range of 65536 but it's OK if we roll over, so | ||
+ | // just count from 0 to 5*65536. Adding 256 to firstPixelHue each time | ||
+ | // means we'll make 5*65536/256 = 1280 passes through this outer loop: | ||
+ | for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) { | ||
+ | for(int i=0; i< | ||
+ | // Offset pixel hue by an amount to make one full revolution of the | ||
+ | // color wheel (range of 65536) along the length of the strip | ||
+ | // (strip.numPixels() steps): | ||
+ | int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels()); | ||
+ | // strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or | ||
+ | // optionally add saturation and value (brightness) (each 0 to 255). | ||
+ | // Here we're using just the single-argument hue variant. The result | ||
+ | // is passed through strip.gamma32() to provide ' | ||
+ | // before assigning to each pixel: | ||
+ | strip.setPixelColor(i, | ||
+ | } | ||
+ | strip.show(); | ||
+ | delay(wait); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // Rainbow-enhanced theater marquee. Pass delay time (in ms) between frames. | ||
+ | void theaterChaseRainbow(int wait) { | ||
+ | int firstPixelHue = 0; // First pixel starts at red (hue 0) | ||
+ | for(int a=0; a<30; a++) { // Repeat 30 times... | ||
+ | for(int b=0; b<3; b++) { // ' | ||
+ | strip.clear(); | ||
+ | // ' | ||
+ | for(int c=b; c< | ||
+ | // hue of pixel ' | ||
+ | // revolution of the color wheel (range 65536) along the length | ||
+ | // of the strip (strip.numPixels() steps): | ||
+ | int hue = firstPixelHue + c * 65536L / strip.numPixels(); | ||
+ | uint32_t color = strip.gamma32(strip.ColorHSV(hue)); | ||
+ | strip.setPixelColor(c, | ||
+ | } | ||
+ | strip.show(); | ||
+ | delay(wait); | ||
+ | firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void servo_porte(){ | ||
+ | for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees | ||
+ | // in steps of 1 degree | ||
+ | myservoP.write(pos); | ||
+ | delay(15); | ||
+ | } | ||
+ | for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees | ||
+ | myservoP.write(pos); | ||
+ | delay(15); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | void ventilateur001(){ | ||
+ | digitalWrite(fanPin1, | ||
+ | analogWrite(fanPin2, | ||
+ | delay(1000); | ||
+ | digitalWrite(fanPin1, | ||
+ | digitalWrite(fanPin2, | ||
+ | delay(1000); | ||
+ | digitalWrite(fanPin1, | ||
+ | analogWrite(fanPin2, | ||
+ | delay(1000); | ||
+ | digitalWrite(fanPin1, | ||
+ | digitalWrite(fanPin2, | ||
+ | delay(1000); | ||
+ | digitalWrite(fanPin1, | ||
+ | analogWrite(fanPin2, | ||
+ | delay(1000); | ||
+ | | ||
+ | / | ||
+ | analogWrite(fanPin2, | ||
+ | delay(1000); | ||
+ | digitalWrite(fanPin1, | ||
+ | digitalWrite(fanPin2, | ||
+ | delay(1000); | ||
+ | } | ||
+ | |||
+ | void affiche(){ | ||
+ | mylcd.clear(); | ||
+ | mylcd.setCursor(2, | ||
+ | mylcd.print(" | ||
+ | mylcd.setCursor(3, | ||
+ | mylcd.print(" | ||
+ | } | ||
+ | |||
+ | void ledON(){ | ||
+ | digitalWrite(led_y, | ||
+ | delay(2000); | ||
+ | } | ||
+ | |||
+ | void ledOFF(){ | ||
+ | digitalWrite(led_y, | ||
+ | delay(2000); | ||
+ | } | ||
+ | |||
+ | void capt_temp(){ | ||
+ | | ||
+ | if (xht.receive(dht)) { //Returns true when checked correctly | ||
+ | Serial.print(" | ||
+ | Serial.print(dht[0]); | ||
+ | Serial.print(" | ||
+ | Serial.print(" | ||
+ | Serial.print(dht[2]); | ||
+ | Serial.println(" | ||
+ | |||
+ | mylcd.setCursor(0, | ||
+ | mylcd.print(" | ||
+ | mylcd.print(dht[2]); | ||
+ | mylcd.print(" | ||
+ | mylcd.setCursor(0, | ||
+ | mylcd.print(" | ||
+ | mylcd.print(dht[0]); | ||
+ | mylcd.print(" | ||
+ | |||
+ | delay(200); | ||
+ | } else { //Read error | ||
+ | Serial.println(" | ||
+ | } | ||
+ | delay(1000); | ||
+ | } | ||
+ | |||
+ | void fenetre(){ | ||
+ | int water_val = analogRead(waterPin); | ||
+ | Serial.println(water_val); | ||
+ | if(water_val > 1500) { | ||
+ | myservoF.write(0); | ||
+ | delay(200); | ||
+ | } | ||
+ | else { | ||
+ | myservoF.write(140); | ||
+ | delay(200); | ||
+ | } | ||
+ | delay(2000); | ||
+ | } | ||
+ | |||
+ | void affichefenetre(){ | ||
+ | int water_val = analogRead(waterPin); | ||
+ | mylcd.clear(); | ||
+ | mylcd.setCursor(2, | ||
+ | mylcd.print(" | ||
+ | mylcd.setCursor(3, | ||
+ | mylcd.print(water_val); | ||
+ | delay(2000); | ||
+ | } | ||
+ | |||
+ | void LED_RVB(){// | ||
+ | colorWipe(strip.Color(255, | ||
+ | colorWipe(strip.Color( | ||
+ | colorWipe(strip.Color( | ||
+ | |||
+ | // Do a theater marquee effect in various colors... | ||
+ | theaterChase(strip.Color(127, | ||
+ | theaterChase(strip.Color(127, | ||
+ | theaterChase(strip.Color( | ||
+ | |||
+ | rainbow(10); | ||
+ | theaterChaseRainbow(50); | ||
+ | } | ||
+ | /* | ||
+ | void RFID(){ | ||
+ | // | ||
+ | if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) { | ||
+ | delay(50); | ||
+ | password = ""; | ||
+ | if(btnFlag == 1) | ||
+ | { | ||
+ | boolean btnVal = digitalRead(btnPin); | ||
+ | if(btnVal == 0) //Swipe the card to open the door and click button 1 to close the door | ||
+ | { | ||
+ | Serial.println(" | ||
+ | mylcd.setCursor(0, | ||
+ | mylcd.print(" | ||
+ | myservoP.write(0); | ||
+ | btnFlag = 0; | ||
+ | } | ||
+ | } | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | // select one of door cards. UID and SAK are mfrc522.uid. | ||
+ | |||
+ | // save UID | ||
+ | Serial.print(F(" | ||
+ | for (byte i = 0; i < mfrc522.uid.size; | ||
+ | Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "); | ||
+ | // | ||
+ | Serial.print(mfrc522.uid.uidByte[i]); | ||
+ | password = password + String(mfrc522.uid.uidByte[i]); | ||
+ | } | ||
+ | // | ||
+ | if(password == " | ||
+ | { | ||
+ | Serial.println(" | ||
+ | mylcd.setCursor(0, | ||
+ | mylcd.clear(); | ||
+ | mylcd.print(" | ||
+ | myservoP.write(180); | ||
+ | password = ""; | ||
+ | btnFlag = 1; | ||
+ | } | ||
+ | else //The card number is wrong,LCD displays error | ||
+ | { | ||
+ | password = ""; | ||
+ | mylcd.setCursor(0, | ||
+ | mylcd.print(" | ||
+ | } | ||
+ | // | ||
+ | } | ||
+ | |||
+ | void ShowReaderDetails() { | ||
+ | // attain the MFRC522 software | ||
+ | byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg); | ||
+ | Serial.print(F(" | ||
+ | Serial.print(v, | ||
+ | if (v == 0x91) | ||
+ | Serial.print(F(" | ||
+ | else if (v == 0x92) | ||
+ | Serial.print(F(" | ||
+ | else | ||
+ | Serial.print(F(" | ||
+ | Serial.println("" | ||
+ | // when returning to 0x00 or 0xFF, may fail to transmit communication signals | ||
+ | if ((v == 0x00) || (v == 0xFF)) { | ||
+ | Serial.println(F(" | ||
+ | } | ||
+ | } | ||
+ | */ | ||
+ | |||
+ | </ | ||
====== SmartHome MicroPython3 ====== | ====== SmartHome MicroPython3 ====== | ||
/home/chanteri/www/fablab37110/data/attic/start/arduino/esp32/smarthome.1756471269.txt.gz · Dernière modification : de admin