Re: Montages ESP32 S3 WROOM
Posté : 11 août 2026, 07:25
Le forum des passionnés de trains miniature, de petites autos etc etc
https://www.forum-passionnement.eu/
Code : Tout sélectionner
/**********************************************************************
Filename : Doorbell
Description : Control active buzzer by button.
Auther : www.freenove.com
Modification: 2024/06/18
**********************************************************************/
#define PIN_BUZZER 14
#define PIN_BUTTON 21
void setup() {
pinMode(PIN_BUZZER, OUTPUT);
pinMode(PIN_BUTTON, INPUT);
}
void loop() {
if (digitalRead(PIN_BUTTON) == LOW) {
digitalWrite(PIN_BUZZER,HIGH);
}else{
digitalWrite(PIN_BUZZER,LOW);
}
}
Comme je l’ai dit ça m’occupe un peu, mais je ne me fait pas trop d’illusion quant au public… les forums n’ont plus la cote face aux réseaux sociaux. Sinon mon forum est opérationnel et actifC'est bien de faire ton forum sur ce que tu fais, j'espère que tu trouveras ton public...
Code : Tout sélectionner
/**********************************************************************
Filename : Alertor
Description : Using software pwm to control passive buzzer by button.
Auther : www.freenove.com
Modification: 2024/06/18
**********************************************************************/
#define BUZZER_PIN 14
#define PIN_BUTTON 21
hw_timer_t * timer = NULL;
bool isAlerting = false;
void IRAM_ATTR onTimer() {
digitalWrite(BUZZER_PIN, !digitalRead(BUZZER_PIN));
}
void setup() {
pinMode(PIN_BUTTON, INPUT);
pinMode(BUZZER_PIN, OUTPUT);
// Set the timer frequency to 1MHz.(see ESP32 Technical Reference Manual for more info).
timer = timerBegin(1000000);
// Attach onTimer function to our timer.
timerAttachInterrupt(timer, &onTimer);
}
void loop() {
if (digitalRead(PIN_BUTTON) == LOW) {
if (!isAlerting) {
isAlerting = true;
// Set alarm, 1ms, repeat, auto-reload value.
timerAlarm(timer, 1000, true, 0);
// Start an alarm
timerStart(timer);
}
alert();
} else {
if (isAlerting) {
isAlerting = false;
timerStop(timer);
digitalWrite(BUZZER_PIN, LOW);
}
}
}
void alert() {
float sinVal;
int toneVal;
for (int x = 0; x < 360; x += 1) {
sinVal = sin(x * (PI / 180));
toneVal = 2000 + sinVal * 500;
timerAlarm(timer, 500000 / toneVal, true, 0);
delay(1);
}
}Code : Tout sélectionner
/**********************************************************************
Filename : SerialPrinter
Description : Use UART send some data to PC, and show them on serial monitor.
Auther : www.freenove.com
Modification: 2024/06/18
**********************************************************************/
void setup() {
Serial.begin(115200);
Serial.println("ESP32 initialization completed!");
}
void loop() {
Serial.printf("Running time : %.1f s\n", millis() / 1000.0f);
delay(1000);
}Code : Tout sélectionner
/**********************************************************************
Filename : SerialRW
Description : Use UART read and write data between ESP32 and PC.
Auther : www.freenove.com
Modification: 2026/01/12
**********************************************************************/
String inputString = ""; // a String to hold incoming data
bool stringComplete = false; // whether the string is complete
void setup() {
Serial.begin(115200);
Serial.println("\nESP32 initialization completed!");
Serial.println("Please input some characters,");
Serial.println("select "Newline" below and Ctrl + Enter to send message to ESP32.");
Serial.println("Ready to receive data...\n");
}
void loop() {
if (Serial.available()) {
inputString = Serial.readStringUntil('\n');
// trim() removes leading and trailing whitespace characters, including \r, \n, tabs, etc.
inputString.trim();
if (inputString.length() > 0) {
stringComplete = true;
}
}
if (stringComplete) {
Serial.printf("inputString: %s\r\n", inputString.c_str());
inputString = "";
stringComplete = false;
}
}


Non, tout est expliqué ici => TutoIl n'y pas de comparaison du texte entré pour effectuer une action donnée
Code : Tout sélectionner
/**********************************************************************
Filename : ADC_DAC
Description : Basic usage of ADC and DAC for esp32.
Auther : www.freenove.com
Modification: 2024/06/18
**********************************************************************/
#define PIN_ANALOG_IN 1
void setup() {
Serial.begin(115200);
}
void loop() {
int adcVal = analogRead(PIN_ANALOG_IN);
double voltage = adcVal / 4095.0 * 3.3;
Serial.printf("ADC Val: %d, \t Voltage: %.2fV\r\n", adcVal, voltage);
delay(200);
}
Exact!L'amélioration pourrait passer par le changement de l'affichage que si la valeur du potentiomètre change.
Code : Tout sélectionner
/**********************************************************************
Filename : TouchRead
Description : Read touch sensor value.
Auther : www.freenove.com
Modification: 2024/06/18
**********************************************************************/
void setup()
{
Serial.begin(115200);
}
void loop()
{
Serial.printf("Touch value: %d \r\n",touchRead(T14)); // get value using T0(GPIO4)
delay(1000);
}Code : Tout sélectionner
/**********************************************************************
Filename : TouchLamp
Description : Control led by touch button.
Auther : www.freenove.com
Modification: 2024/06/18
**********************************************************************/
#define PIN_LED 21
#define PRESS_VAL 200000 //Set a threshold to judge touch
#define RELEASE_VAL 60000 //Set a threshold to judge release
bool isProcessed = false;
void setup() {
Serial.begin(115200);
pinMode(PIN_LED, OUTPUT);
}
void loop() {
if (touchRead(T14) < PRESS_VAL) {
if (!isProcessed) {
isProcessed = true;
Serial.println("Touch detected! ");
reverseGPIO(PIN_LED);
}
}
if (touchRead(T14) > RELEASE_VAL) {
if (isProcessed) {
isProcessed = false;
Serial.println("Released! ");
}
}
}
void reverseGPIO(int pin) {
digitalWrite(pin, !digitalRead(pin));
}
Code : Tout sélectionner
/**********************************************************************
Filename : SoftLight
Description : Controlling the brightness of LED by potentiometer.
Auther : www.freenove.com
Modification: 2024/06/18
**********************************************************************/
#define PIN_ANALOG_IN 1
#define PIN_LED 14
#define CHAN 0
void setup() {
ledcAttachChannel(PIN_LED, 1000, 12, CHAN);
}
void loop() {
int adcVal = analogRead(PIN_ANALOG_IN); //read adc
int pwmVal = adcVal; // adcVal re-map to pwmVal
ledcWrite(PIN_LED, pwmVal); // set the pulse width.
delay(10);
}Code : Tout sélectionner
/**********************************************************************
Filename : SoftColorfulLight
Description : Controlling the color of RGBLED by potentiometer.
Auther : www.freenove.com
Modification: 2024/06/18
**********************************************************************/
const byte adcChns[] = {12, 13, 14}; //define led pins
const byte ledPins[] = {38, 39, 40}; //define the pwm channels
const byte pwmChns[] = { 0, 1, 2}; // define the adc channels
int colors[] = {0, 0, 0}; // red, green ,blue values of color.
void setup() {
for (int i = 0; i < 3; i++) { //setup the pwm channels
ledcAttachChannel(ledPins[i], 1000, 8, pwmChns[i]);
}
}
void loop() {
for (int i = 0; i < 3; i++) {
colors[i] = map(analogRead(adcChns[i]), 0, 4095, 0, 255); //calculate color value.
ledcWrite(ledPins[i], 256 - colors[i]); //set color
}
delay(10);
}