Poradna

Datum
Vložil
Titulek

Problém s sérivým monitorem

Dobrý večer, Pro svůj projekt počítačem řízeného zdroje napětí, potřebuji Arduinu posílat data přes sériový monitor v IDE Arduino, přesněji jde o velikost žádaného napětí a hladiny omezení proudu. Zkoušel jsem tenhle prográmek, ale mám problém se splněním konečné podmínky rozpoznání znaku char. „n“, prográmek je stažen ze stránek Arduino tutorial a je jen inspirativní, hlavně mi jde o to, abych poslal znak pro rozlišení napětí proudu a hodnotu na kterou se májí nastavit.
// pins for the LEDs:
const int redPin = 3;
const int greenPin = 5;
const int bluePin = 6;

void setup() {
// initialize serial:
Serial.begin(9600);
// make the pins outputs:
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);

}

void loop() {
// if there's any serial available, read it:
while (Serial.available() > 0) {

// look for the next valid integer in the incoming serial stream:
int red = Serial.parseInt();
// do it again:
int green = Serial.parseInt();
// do it again:
int blue = Serial.parseInt();

// look for the newline. That's the end of your sentence:
if (Serial.read() == '\n') {
// constrain the values to 0 - 255 and invert
// if you're using a common-cathode LED, just use "constrain(color, 0, 255);"
red = 255 - constrain(red, 0, 255);
green = 255 - constrain(green, 0, 255);
blue = 255 - constrain(blue, 0, 255);

// fade the red, green, and blue legs of the LED:
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);

// print the three numbers in one string as hexadecimal:
Serial.print(red, HEX);
Serial.print(green, HEX);
Serial.println(blue, HEX);
}
}
}

Zpět na diskuzi

Vyhledávání

arduino8.cz © 2015 Všechna práva vyhrazena.