const int SENSOR = A0;
const int LED = 13;
int val = 0;
int max = 0;
void setup() {
Serial.begin(9600);
pinMode(SENSOR, INPUT);
pinMode(LED, OUTPUT);
}
void loop() {
val = analogRead(SENSOR);
if (val > max) {
max = val;
}
String space = " ";
Serial.println(max + space + val);
if (val > 10) {
digitalWrite(LED, HIGH);
} else {
digitalWrite(LED, LOW);
}
delay(20);
}
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme