bonjour,
Alors voila je débute sur arduino et j'aurais besoin d'aide pour le programme, J'ai bidouillé comme j'ai pu et sa donne sa :
int brightness = 0;
int fadeAmount = 5;
const int ledPin = 9;
int ledState = 0; // ledState used to set the LED
unsigned long DELMIC = 0;
long previousMillis = 0; // will store last time LED was updated
long interval = 1000;
void setup()
{
Serial.begin(9600);
// prints title with ending line break
Serial.println("mise au point affichage");
Serial.println("selection du mode de commande");
Serial.println("1 : test led");
Serial.println("2 : frequence de xhz");
Serial.println("3 : definir une frequence entre 1 et 1 000 000");
pinMode(ledPin, OUTPUT);
}
void loop()
{
unsigned long currentMillis = millis();
if (Serial.available() > 0) {
int DELMIC = Serial.read();
Serial.println(DELMIC, DEC);
// do something different depending on the character received.
// The switch statement expects single number values for each case;
// in this exmaple, though, you're using single quotes to tell
// the controller to get the ASCII value for the character. For
// example 'a' = 97, 'b' = 98, and so forth:
switch (DELMIC) {
case '1':
for(;DELMIC < 50;) {
analogWrite(ledPin, brightness);
DELMIC = Serial.read();
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;
}
// wait for 30 milliseconds to see the dimming effect
delay(5);
}
break;
case '2':
if (DELMIC==50) {
for(;DELMIC < 51;){
DELMIC = Serial.read();
analogWrite(ledPin, 0); // set the LED on
delay(100); // wait for a second
analogWrite(ledPin, 255); // set the LED off
delay(100);
}
}
break;
/* case '3':
for(;DELMIC == 51;) {
Serial.println("definir une frequence");
Serial.read();
Serial.print("I received: ");
if (DELMIC == 113){
Serial.println(DELMIC, DEC);
DELMIC = 1/DELMIC;
DELMIC = DELMIC*500000;
Serial.println(DELMIC, DEC);
Serial.println('A');
}
analogWrite(ledPin, 0); // sets the pin on
delayMicroseconds(DELMIC); // pauses
analogWrite(ledPin, 255); // sets the pin off
delayMicroseconds(DELMIC); // pauses
}
break;
*/
default:
// turn all the LEDs off:
Serial.println("erreur");
// if (DELMIC == 'q') {
analogWrite(ledPin, 255);
// }
}
}
}
Alors ce programme donne le choix entre éclairer progressivement la led la faire clignoter, et donc définir une fréquence via le port série...
J'ai du mal avec les conditions de sortie des boucles, mais c'est surtout la récupération de la donné sur le port série ( la fréquence doit allez de 1 à 1 000 000)que je ne comprend pas trop comment prendre les caractères dans le tableau et les "rassembler", si quelqu'un pouvais m'expliquer.
Je vous remercie d'avance pour le coup de pousse