





Ce n'est pas bien de copier sur PatrickUne façon pour ne pas se faire "shield" avec un support


Code : Tout sélectionner
/**********************************************************************
Filename : ButtonAndLed
Description : Control led by button.
Auther : www.freenove.com
Modification: 2024/06/18
**********************************************************************/
#define PIN_LED 2
#define PIN_BUTTON 13
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin PIN_LED as an output.
pinMode(PIN_LED, OUTPUT);
pinMode(PIN_BUTTON, INPUT);
}
// the loop function runs over and over again forever
void loop() {
if (digitalRead(PIN_BUTTON) == LOW) {
digitalWrite(PIN_LED,HIGH);
}else{
digitalWrite(PIN_LED,LOW);
}
}



Code : Tout sélectionner
/**********************************************************************
Filename : TableLamp
Description : Control led by button.
Auther : www.freenove.com
Modification: 2024/06/18
**********************************************************************/
#define PIN_LED 2
#define PIN_BUTTON 13
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin PIN_LED as an output.
pinMode(PIN_LED, OUTPUT);
pinMode(PIN_BUTTON, INPUT);
}
// the loop function runs over and over again forever
void loop() {
if (digitalRead(PIN_BUTTON) == LOW) {
delay(20);
if (digitalRead(PIN_BUTTON) == LOW) {
reverseGPIO(PIN_LED);
}
while (digitalRead(PIN_BUTTON) == LOW);
delay(20);
//while (digitalRead(PIN_BUTTON) == LOW);
}
}
void reverseGPIO(int pin) {
digitalWrite(pin, !digitalRead(pin));
}

Code : Tout sélectionner
/**********************************************************************
Filename : FlowingLight
Description : Using ledbar to demonstrate flowing lamp.
Auther : www.freenove.com
Modification: 2022/10/20
**********************************************************************/
byte ledPins[] = {21, 47, 48, 38, 39, 40, 41, 42, 2, 1};
int ledCounts;
void setup() {
ledCounts = sizeof(ledPins);
for (int i = 0; i < ledCounts; i++) {
pinMode(ledPins[i], OUTPUT);
}
}
void loop() {
for (int i = 0; i < ledCounts; i++) {
digitalWrite(ledPins[i], HIGH);
delay(100);
digitalWrite(ledPins[i], LOW);
}
for (int i = ledCounts - 1; i > -1; i--) {
digitalWrite(ledPins[i], HIGH);
delay(100);
digitalWrite(ledPins[i], LOW);
}
}




Code : Tout sélectionner
/**********************************************************************
Filename : BreathingLight
Description : Make led light fade in and out, just like breathing.
Auther : www.freenove.com
Modification: 2024/06/18
**********************************************************************/
#define PIN_LED 2 //define the led pin
#define CHN 0 //define the pwm channel
#define FRQ 1000 //define the pwm frequency
#define PWM_BIT 8 //define the pwm precision
void setup() {
ledcAttachChannel(PIN_LED, FRQ, PWM_BIT, CHN); //attach the led pin to pwm channel
}
void loop() {
for (int i = 0; i < 255; i++) { //make light fade in
ledcWrite(PIN_LED, i);
delay(10);
}
for (int i = 255; i > -1; i--) { //make light fade out
ledcWrite(PIN_LED, i);
delay(10);
}
}

Code : Tout sélectionner
/**********************************************************************
Filename : FlowingLight2
Description : More cool flowing light.
Auther : www.freenove.com
Modification: 2024/06/18
**********************************************************************/
const byte ledPins[] = {21, 47, 38, 39, 40, 41, 42, 2}; //define led pins
const byte chns[] = {0, 1, 2, 3, 4, 5, 6, 7}; //define the pwm channels
const int dutys[] = {0, 0, 0, 0, 0, 0, 0, 0,
1023, 512, 256, 128, 64, 32, 16, 8,
0, 0, 0, 0, 0, 0, 0, 0
}; //define the pwm dutys
int ledCounts;
int delayTimes = 50; //flowing speed ,the smaller, the faster
void setup() {
ledCounts = sizeof(ledPins); //get the led counts
for (int i = 0; i < ledCounts; i++) { //setup the pwm channels
ledcAttachChannel(ledPins[i], 1000, 10, chns[i]);
}
}
void loop() {
for (int i = 0; i < 16; i++) { //flowing one side to other side
for (int j = 0; j < ledCounts; j++) {
ledcWrite(ledPins[j], dutys[i + j]);
}
delay(delayTimes);
}
for (int i = 0; i < 16; i++) { //flowing one side to other side
for (int j = ledCounts - 1; j > -1; j--) {
ledcWrite(ledPins[j], dutys[i + (ledCounts - 1 - j)]);
}
delay(delayTimes);
}
}


Code : Tout sélectionner
const byte ledPins[] = {38, 39, 40}; //define red, green, blue led pins
const byte chns[] = {0, 1, 2}; //define the pwm channels
int red, green, blue;
void setup() {
for (int i = 0; i < 3; i++) { //setup the pwm channels,1KHz,8bit
ledcAttachChannel(ledPins[i], 1000, 8, chns[i]);
}
}
void loop() {
red = random(0, 256);
green = random(0, 256);
blue = random(0, 256);
setColor(red, green, blue);
delay(200);
}
void setColor(byte r, byte g, byte b) {
ledcWrite(ledPins[0], 255 - r); //Common anode LED, low level to turn on the led.
ledcWrite(ledPins[1], 255 - g);
ledcWrite(ledPins[2], 255 - b);
}

Code : Tout sélectionner
const byte ledPins[] = {38, 39, 40}; //define led pins
const byte chns[] = {0, 1, 2}; //define the pwm channels
void setup() {
for (int i = 0; i < 3; i++) { //setup the pwm channels
ledcAttachChannel(ledPins[i], 1000, 8, chns[i]);
}
}
void loop() {
for (int i = 0; i < 256; i++) {
setColor(wheel(i));
delay(20);
}
}
void setColor(long rgb) {
ledcWrite(ledPins[0], 255 - (rgb >> 16) & 0xFF);
ledcWrite(ledPins[1], 255 - (rgb >> 8) & 0xFF);
ledcWrite(ledPins[2], 255 - (rgb >> 0) & 0xFF);
}
long wheel(int pos) {
long WheelPos = pos % 0xff;
if (WheelPos < 85) {
return ((255 - WheelPos * 3) << 16) | ((WheelPos * 3) << 8);
} else if (WheelPos < 170) {
WheelPos -= 85;
return (((255 - WheelPos * 3) << 8) | (WheelPos * 3));
} else {
WheelPos -= 170;
return ((WheelPos * 3) << 16 | (255 - WheelPos * 3));
}
}

Code : Tout sélectionner
/**********************************************************************
Filename : NeoPixel
Description : Basic usage of LEDPixel,
Make the strip light up in different colors gradually.
Auther : www.freenove.com
Modification: 2024/06/18
**********************************************************************/
#include "Freenove_WS2812_Lib_for_ESP32.h"
#define LEDS_COUNT 8 // The number of led
#define LEDS_PIN 48 // define the pin connected to the Freenove 8 led strip
#define CHANNEL 0 // RMT module channel
Freenove_ESP32_WS2812 strip = Freenove_ESP32_WS2812(LEDS_COUNT, LEDS_PIN, CHANNEL, TYPE_GRB);
int m_color[5][3] = { {255, 0, 0}, {0, 255, 0}, {0, 0, 255}, {255, 255, 255}, {0, 0, 0} };
int delayval = 100;
void setup() {
strip.begin();
strip.setBrightness(10);
}
void loop() {
for (int j = 0; j < 5; j++) {
for (int i = 0; i < LEDS_COUNT; i++) {
strip.setLedColorData(i, m_color[j][0], m_color[j][1], m_color[j][2]);// Set color data.
strip.show(); // Send color data to LED, and display.
delay(delayval);// Interval time of each LED.
}
delay(500); // Interval time of each group of colors.
}
}

Code : Tout sélectionner
/**********************************************************************
Filename : RainbowLight
Description : Make the strip light up in rainbow colors.
Auther : www.freenove.com
Modification: 2024/06/18
**********************************************************************/
#include "Freenove_WS2812_Lib_for_ESP32.h"
#define LEDS_COUNT 8
#define LEDS_PIN 48
#define CHANNEL 0
Freenove_ESP32_WS2812 strip = Freenove_ESP32_WS2812(LEDS_COUNT, LEDS_PIN, CHANNEL, TYPE_GRB);
void setup() {
strip.begin();
}
void loop() {
for (int j = 0; j < 255; j += 2) {
for (int i = 0; i < LEDS_COUNT; i++) {
strip.setLedColorData(i, strip.Wheel((i * 256 / LEDS_COUNT + j) & 255));
}
strip.show();
delay(5);
}
}Utilisateurs parcourant ce forum : Aucun utilisateur enregistré et 1 invité