Controlling the Arduino over the serial connection

Aus DL8RDS Wiki
Wechseln zu: Navigation, Suche

2009-09-19 The following program is there to demostrate how I can talk to the Arduino over the serial interface: After sending a character "B", the blinking goes off, and after sending a "A", it will start again:

int potiPin = 0;
int potiVal = 0;
int blink = 1;
int ledPin = 2;

void setup() {
  Serial.begin(9600);
  int potiPin = 0;
  pinMode(ledPin, OUTPUT);
}

void loop() {
  int potiVal = analogRead(potiPin);
  //Serial.println("Poti-Wert:");
  if (Serial.available() > 0) {
     char b = Serial.read();
     if (b == 65) {
        blink = 1;
     }
     if (b == 66) {
        blink = 0;
     }
  }

  if (blink == 1) {
     digitalWrite(ledPin, HIGH);
     delay(100);
     digitalWrite(ledPin,LOW);
     delay(potiVal*2);
  } else {
     digitalWrite(ledPin, LOW);
  }

  Serial.println(potiVal);
  //Serial.println("-------------");
  delay(10);
}