Bonjour,
j'ai un projet de pilotage d'un ruban LED et un ventilateur par un Arduino Uno Rev2.
J'ai fait pour cela une petite carte d'interface.
J'alimente le tout par un bloc secteur 12V externe.
Chose étrange c'est que quand j'alimente le tout par l'alim 12V cela ne fonctionne pas (boutons, encodeur et LEDs inactifs). Par contre quand je connecte le tout à l'USB pour transférer mon programme (le tout toujours alimenté en 12V) tout fonctionne ! Le plus étrange étant qu'une fois dans cet état, même en enlevant le cable USB cela continue de fonctionner... Si j'éteins le 12V et que je rallume, cela ne fonctionne plus de nouveau.
Une suggestion ? Problème matériel ? logiciel ?
Ci joint mon schéma et mon code.
#include <TM1637Display.h>
#define ROTARY_CLK 2
#define ROTARY_DT 3
#define ROTARY_SW 4
#define DISPLAY_CLK 9
#define DISPLAY_DIO 7
#define BUTTON_PIN 6
#define LED_PIN 8
int buttonState = 0; // variable for reading the pushbutton status
int timerSec = 0;
int timerMin = 0;
int timerSetMode = 1; // toggle set of min or sec. Default = seconds
int rot_clkValue = LOW;
int rot_dtValue;
int rot_lastState = LOW;
int rot_swState;
unsigned long lastRotarySwPress = 0; // tempo 50ms to avoid click errors
unsigned long lastRotClk = 0; // tempo 50ms to avoid rotation errors
TM1637Display display = TM1637Display(DISPLAY_CLK, DISPLAY_DIO);
int allON[] = { 0xff, 0xff, 0xff, 0xff };
int allOFF[] = { 0x00, 0x00, 0x00, 0x00 };
void setup() {
pinMode(ROTARY_CLK, INPUT);
pinMode(ROTARY_DT, INPUT);
pinMode(ROTARY_SW, INPUT_PULLUP);
pinMode(DISPLAY_CLK, INPUT);
pinMode(DISPLAY_DIO, INPUT);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN,LOW);
pinMode(BUTTON_PIN, INPUT);
display.setBrightness(1);
display.clear();
//Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(ROTARY_CLK), onRotaryClkChange, CHANGE);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(BUTTON_PIN);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(LED_PIN, HIGH);
} else {
// turn LED off:
digitalWrite(LED_PIN, LOW);
}
// Read the Rotary button state
int rot_swState = digitalRead(ROTARY_SW);
//If we detect LOW signal, button is pressed
if (rot_swState == LOW) {
//if 50ms have passed since last LOW pulse, it means that the
//button has been pressed, released and pressed again
if (abs(millis()) - lastRotarySwPress > 50) {
timerSetMode *=-1;
}
// Remember last button press event
lastRotarySwPress = millis();
}
}
void onRotaryClkChange() {
String msg; // DEBUG !!
rot_clkValue = digitalRead(ROTARY_CLK);
if (rot_lastState == LOW && rot_clkValue == HIGH) {
rot_dtValue = digitalRead(ROTARY_DT);
if (rot_dtValue == LOW) {
if (timerSetMode == 1) {
timerSec++;
msg = "\nOrientation : Positif / Mode : Sec / timerSec : " + String(timerSec);
Serial.println(msg);
}
else {
timerMin++;
msg = "\nOrientation : Positif / Mode : Min / timerMin : " + String(timerMin);
Serial.println(msg);
}
}
else {
if (timerSetMode == -1) {
timerSec--;
msg = "\nOrientation : Negatif / Mode : Sec / timerSec : " + String(timerSec);
Serial.println(msg);
}
else {
timerMin--;
msg = "\nOrientation : Negatif / Mode : Min / timerMin : " + String(timerMin);
Serial.println(msg);
}
}
display.showNumberDecEx(timerSec, 0b01000000, false, 2, 2);
display.showNumberDecEx(timerMin, 0b01000000, false, 2, 0);
}
rot_lastState = rot_clkValue;
}
