/*Header
Hardware and programming to better understand and use analogRead
In this cricuit we have a potentiometer - a variable resistor
Which by turning the knob (changing the resistance) we can
change the amount of voltage the potentiometer disappates
For you circuits wizzes a potentiometer is variable voltage divider
Think about how we could display and view readings
and how we could use those readings to alter other functions
In this example we want to use those readings to let us know
IF the reading is below a value, and IF so, we should print
a statement to the serial monitor
*/
//Global variable and pin delcaration
//are using analog pin A0 --> already declared
//pins declared
//variables?
int Bread; //analog reading from potentiometer (A0)
int BreadMapped; //new mapped value
void setup() {
// put your setup code here, to run once:
//no need to pinMode
//initialize serial monitor plotter
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
//now read/sense voltage from circuit | sensor/ read-command
Bread = analogRead(A0);
Serial.println(Bread);
//I want to display 'LEFT' IF the value is below half-the 10bit value
//and 'right' if the value is above that 10-bit value
if(Bread <= 512){
//where everything happens IF true
Serial.println("LEFT");
} else {
Serial.println("RIGHT");
}
//if(condition){
//do stuff IF TRUE
//} else {
//do stuff ELSE TRUE
//}
//Now these values correspond to what range of voltages?
//what if I wanted that voltage instead of the 10bit value
//we can MAP a value in a specified range to a value within another range
//0-5V
//map funciton
//BreadMapped = map(Bread, 0,1023,0,5); //all integers 0-5
//get creative use map to get voltage to x.xx
//BreadMapped = map(Bread,0,1023,0,500);//all 0-500 just divide by 100
//can I map to negative values and other directions
//two numbers: 50 -412
BreadMapped = map(Bread,0,1023,50,-412);
//YES - negative values and OTHER DIRECTIONS
Serial.println(BreadMapped);
//add a nice little .1s delay for viewing purposes
delay(100);//ms
}