/*
Blink
https://www.arduino.cc/en/Tutorial/BuiltInExamples/Blink
Fade
https://www.arduino.cc/en/Tutorial/BuiltInExamples/Fade
ReadAnalogVoltage
https://www.arduino.cc/en/Tutorial/BuiltInExamples/ReadAnalogVoltage
DigitalReadSerial
https://www.arduino.cc/en/Tutorial/BuiltInExamples/DigitalReadSerial
*/
int led = 9; // the PWM pin the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
// digital pin 2 has a pushbutton attached to it. Give it a name:
int pushButton = 2;
// the setup function runs once when you press reset or power the board
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
// declare pin 9 to be an output:
pinMode(led, OUTPUT);
// make the pushbutton's pin an input:
pinMode(pushButton, INPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for a second
// set the brightness of pin 9:
analogWrite(led, brightness);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
// wait for 30 milliseconds to see the dimming effect
delay(30);
//start of readanalogue voltage
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
// print out the value you read:
Serial.println(voltage);
//end of analogue voltage
// read the input pin:
int buttonState = digitalRead(pushButton);
// print out the state of the button:
Serial.println(buttonState);
delay(1); // delay in between reads for stability
}