0% found this document useful (0 votes)
84 views

Arduino

The document contains code to read the state of a button connected to analog pin A0 and send the character 'a' or 'b' over serial based on if the button is pressed or not.

Uploaded by

api-304291912
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views

Arduino

The document contains code to read the state of a button connected to analog pin A0 and send the character 'a' or 'b' over serial based on if the button is pressed or not.

Uploaded by

api-304291912
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

const int buttonPin = 2; // Analog In A0

//const int ledPin = 13; // onboard Pin 13 LED


int buttonState = 0;
void setup() {
Serial.begin(9600);
//pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
}
void loop() {
buttonState = digitalRead(buttonPin);
//int brightness = digitalRead(buttonPin); // read value range 0~1023
if (buttonState == HIGH) {
// turn LED on:
//digitalWrite(ledPin, 1);
//Serial.println("a");
Serial.write("a");
//int sensorValue = analogRead(buttonState);
}else{
//Serial.println("b");
Serial.write("b");
}
delay(100);
}

You might also like