Analog and digital INPUTS and OUTPUTS

Digital OUTPUT


//the objective is to switch ON and OFF a LED when I press 1 or 0 in the Arduino console
const int outPin= 3; // constant integer (integer numbers)
void seup(){ //settings, it runs once
pinMode(outPin,OUTPUT); //built-in function, has two arguments or parameter: pin name or pin number and INPUT or OUTPUT
Serial.begin(9600); 
/*Serial is a class or a type of object and also the principal class of Serial library that is included in the core of Arduino. The class is always in capital letters, 
the dot syntax indecates a method with lower cases: Class.method or object.method (parameters). A method is a set of functions (a set of instructions). Serial class
accepts four methods minimum(begin, print, println, read,...). Serial.begin needs a parameter (bouds). Serial.println, if it's between quotation marks, will write what
we exactly put, and if we don't put it between quotation marks, it's a variable. The difference between Serial.println and Serial.print is that Serial.println changes
the line and Serail.print writes everything in the same line.
LANGUAGE --within--> LIBRARIES --within--> CLASSES --within--> METHODS --within--> FUNCTIONS --within--> INSTRUCTIONS*/
Serial.println("Enter 1 or 0");}
void loop(){ //never stops (it runs forever). ~50Hz --> ~50 times/second
if (Serial.available() >0){ 
char ch=Serial.read(); // has to be a character
if (ch== '1'){ //if char=1, LED ON
digitalWrite(outPin,HIGH); //LED ON
else if (ch== '0'){ //if char=0, LED OFF
digitalWrite(outPin,LOW);} //LED OFF
}}

Digital INPUT


const int inputPin= 5;
void seup(){
pinMode(inputPin,INPUT);
Serial.begin(9600);}
void loop(){
int reading= digitalRead(inputPin);
Serial.println(reading);
delay(1000);}

Analog OUTPUT


const int outputPin= 3;
void setup(){
pinMode(outputPin,OUPUT);
Serial.begin(9600);
Serial.println("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 setup(){
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);}