Hi there... I'm trying to use the serial monitor to gather data from a photocell connected to my arduino uno, and have the arduino stop sending data when I activate a pushbutton. It isn't working, and I can't figure out why. Help will be greatly appreciated!
So... what I've got so far does give me information in the serial monitor, BUT it doesn't stop when I push the button. Why?
the photocell is on A0, and the button is on D4.
int photoPin = A0;
int inPin = 4;
int val = 0;
void setup() {
Serial.begin(1200);
pinMode (photoPin, INPUT);
pinMode (inPin, INPUT);
}
void loop() {
Serial.println(analogRead(A0));
delay(2);
val == digitalRead(4);
if (val == HIGH) {Serial.end();}
}
However, I want it to completely stop when I press the button, so that I don't have to hold the button down forever. I do realize that a slide switch would work, but I don't have any at the moment... Any other ideas?
Yes, I did. However, it simply caused the serialprint to stop on its own, without waiting for the pushbutton's signal, a few milliseconds after starting.