User Tools

Site Tools


projets:fuz:webduino

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
projets:fuz:webduino [2019-12-03 21:20] – [Wiring and flashing] Lomanicprojets:fuz:webduino [2019-12-03 21:28] – [Components] document RGB LED Lomanic
Line 55: Line 55:
 I got blink sketch using LED_BUILTIN (2) I got blink sketch using LED_BUILTIN (2)
  
 +==== RGB LED ====
 +
 +<code c++>
 +/***
 +   RGB sketch for webduino smart
 +   Board:   ESP8266
 +
 +*/
 +
 +#include <Arduino.h>
 +
 +// according to https://webduino.io/en/tutorials/smart-01-information.html#on-board-components-and-pins
 +#define GPIO_GREEN_RGB 12
 +#define GPIO_BLUE_RGB  13
 +#define GPIO_RED_RGB 15
 +#define GPIO_MICRO_SWITCH_BUTTON 4
 +
 +// https://create.arduino.cc/projecthub/muhammad-aqib/arduino-rgb-led-tutorial-fc003e
 +void RGB_color(int red_light_value, int green_light_value, int blue_light_value) {
 +  analogWrite(GPIO_RED_RGB, red_light_value);
 +  analogWrite(GPIO_GREEN_RGB, green_light_value);
 +  analogWrite(GPIO_BLUE_RGB, blue_light_value);
 +}
 +
 +void showColor(int color) {
 +  Serial.printf("Color %d\n", color);
 +  switch (color) {
 +    case 0:
 +      RGB_color(255, 0, 0); // Red
 +      break;
 +    case 1:
 +      RGB_color(0, 255, 0); // Green
 +      break;
 +    case 2:
 +      RGB_color(255, 255, 125); // Raspberry
 +      break;
 +    case 3: // CYAN
 +      RGB_color(0, 255, 255); // Cyan
 +      break;
 +    case 4: // BLUE?
 +      RGB_color(255, 0, 255); // Magenta
 +      break;
 +    case 5: // GREEN
 +      RGB_color(255, 255, 0); // Yellow
 +      break;
 +    case 6:
 +      RGB_color(255, 255, 255); // White
 +    default:
 +      RGB_color(0, 0, 0); // Disabled
 +  }
 +}
 +
 +void setup() {
 +  Serial.begin(115200);
 +  delay(10);
 +  Serial.println();
 +  Serial.println(F("Webduino smart RGB sketch: push the micro switch button to loop over colors"));
 +
 +  pinMode(GPIO_GREEN_RGB, OUTPUT);
 +  pinMode(GPIO_BLUE_RGB, OUTPUT);
 +  pinMode(GPIO_RED_RGB, OUTPUT);
 +}
 +
 +int color = 0;
 +void loop() {
 +  if (digitalRead(GPIO_MICRO_SWITCH_BUTTON) == LOW) {
 +    Serial.println(F("Button pressed"));
 +    color = ((color + 1) % 7);
 +    showColor(color);
 +    delay(200);
 +  }
 +}
 +</code>
 ===== OTA ===== ===== OTA =====
 See https://github.com/esp8266/Arduino/tree/master/libraries/ArduinoOTA/examples See https://github.com/esp8266/Arduino/tree/master/libraries/ArduinoOTA/examples
projets/fuz/webduino.txt · Last modified: 2023-02-02 22:06 by 127.0.0.1