Bonjour, je travail actuellement sur le développement d'un programme permettant de contrôler des leds RGB par infrarouge, j'ai donc fais ce programme cependant mes conditions ne font pas correctement quand je décommante toutes les touches, bug du compilo ?
//2.4 > Envoi d'un signal IR ON/OFF Téléviseur Philips.
int IRledPin = 13; //Variable IRledPin associée à broche n°13
String inputString = ""; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete
/**** ICI je déclare mes int[] qui définissent les boutons (on_key,off_key,etc...).****/
void setup() {
pinMode(IRledPin, OUTPUT); //Broche N°13 est une sortie.
Serial.begin(9600); //Initialisation Serial Monitor.
inputString.reserve(200);
}
void send_key(int sizeKey,int key[])
{
for(int i = 0; sizeKey >= i; i++)
{
if ( (i % 2) == 0) {
pulseIR(key[i]);
} else {
delayMicroseconds(key[i]);
}
}
}
void loop() {
if (stringComplete) {
Serial.println(inputString);
if(inputString == "on\n")
{
send_key(sizeof(on_key),on_key);
}
if(inputString == "off\n")
{
send_key(sizeof(off_key),off_key);
}
if(inputString == "reset\n")
{
send_key(sizeof(reset_key),reset_key);
}
if(inputString == "time-\n")
{
send_key(sizeof(clock_left_key),clock_left_key);
}
if(inputString == "time+\n")
{
send_key(sizeof(clock_right_key),clock_right_key);
}
if(inputString == "run\n")
{
send_key(sizeof(run_key),run_key);
}
if(inputString == "rgb\n")
{
send_key(sizeof(rgb_key),rgb_key);
}
if(inputString == "dimmer-\n")
{
send_key(sizeof(dimmer_down_key),dimmer_down_key);
}
if(inputString == "dimmer+\n")
{
send_key(sizeof(dimmer_up_key),dimmer_up_key);
}
if(inputString == "r\n")
{
send_key(sizeof(r_key),r_key);
}
if(inputString == "g\n")
{
send_key(sizeof(g_key),g_key);
}
/*if(inputString == "b\n")
{
send_key(sizeof(b_key),b_key);
}
if(inputString == "orange\n")
{
send_key(sizeof(orange_key),orange_key);
}
if(inputString == "green\n")
{
send_key(sizeof(green_key),green_key);
}
if(inputString == "blue\n")
{
send_key(sizeof(blue_key),blue_key);
}
if(inputString == "rose\n")
{
send_key(sizeof(rose_key),rose_key);
}
if(inputString == "yellow\n")
{
send_key(sizeof(yellow_key),yellow_key);
}
if(inputString == "blue_light\n")
{
send_key(sizeof(blue_light_key),blue_light_key);
}
if(inputString == "rose_light\n")
{
send_key(sizeof(rose_light_key),rose_light_key);
}
if(inputString == "yellow_light\n")
{
send_key(sizeof(yellow_light_key),yellow_light_key);
}
if(inputString == "blank\n")
{
send_key(sizeof(blank_key),blank_key);
}*/
// clear the string:
inputString = "";
stringComplete = false;
}
}
void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline, set a flag
// so the main loop can do something about it:
if (inChar == '\n') {
stringComplete = true;
}
}
}
// Cette fonction envoie une impulsion d'une fréquence de 38 kHz à la broche n°13.
void pulseIR(long microsecs) {
cli();
while (microsecs > 0) {
// 38 kHz correspond environ à 13 microsecondes à l'état haut et 13 à l'état bas.
digitalWrite(IRledPin, HIGH); // Cette instruction met environ 3 microsecondes à s'effectuer.
delayMicroseconds(10); // On attend 10 microsecondes
digitalWrite(IRledPin, LOW); // Cette instruction met environ 3 microsecondes à s'effectuer.
delayMicroseconds(10); // On attend 10 microsecondes
// En tout, cela met 26 microsecondes.
microsecs -= 26;
}
sei();
}
lorsque je décommante les autres touches rien ne fonctionne, le simple faite d'ajouter UNE SEUL touche fais buger, comme s'il y avait une limite, que faire ?
Merci