Go Down

Topic: how to read analog value continuous with Serial.read() (Read 1 time) previous topic - next topic

wildbill

Can you have another go at explaining what you want it to do?

That looks like it will keep reporting one sensor value (which may vary) until you tell it to report another by sending another character.

mickeleckorn

i want my program to receive analog value from analog pin A0 A1 A2 selected by sending character in serial monitor.

AWOL

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

mickeleckorn

Thanks all i'm finish my code, serial monitor can read analog value continuous now.
Code: [Select]
 const int ledPin = 13;
void setup() {
 Serial.begin(9600);
 pinMode(ledPin, OUTPUT);
 pinMode(9, OUTPUT);
}
int incomingByte;
void loop() {
 int sensorValue1 = analogRead(A0);
 int sensorValue2 = analogRead(A1);
 int sensorValue3 = analogRead(A2);
 if (Serial.available() ) {
 // read the oldest byte in the serial buffer:
   incomingByte = Serial.read();
  }
 switch (incomingByte) {
   case 'a':
      Serial.println(sensorValue1);
      break;
   case 'b':
      Serial.println(sensorValue2);
      break;
   case 'c':
      Serial.println(sensorValue3);
      break;
   case 'H':
      digitalWrite(ledPin, HIGH);
      break;
   case 'L':
      digitalWrite(ledPin, LOW);
      break;
 }
   delay(300);
   }

 
 
   

Grumpy_Mike

Quote
but this not work ,program still monitoring single value.

Have you set the serial monitor to not send any new line characters?
Select "no line ending" from the drop down at the bottom corner of the window.

Go Up