Apunts

Analog output


const int outputPin = 3
void setup(){
pinMode(outputPin, OUTPUT);
Serial.begin(9600);
Serial.printIn("Enter Volts: 0-5");}
void loop(){
if(Serial.available > 0){
float volts = Serial.parseFloat();
int pwmValue = volts*255.0/5.0;
analogWrite(outputPin, pwmValue);}}

Analog Input


const int analogPin = A0;
void(){
Serial.begin(9600};}
void loop(){
int reading = analogRead(analogPin);
float voltage = reading/204.6;
Serial.print("Reading=")
Serial.print(reading);
Serial.print("\t\tVolt=");
Serial.println(voltage);
delay(500);
}