/*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
//pin declarations - A0 - we do not need to initialize analog pins
// global variables
int IDontKnow; //read out analog signal to
int IDontKnowMapped;
void setup() {
// put your setup code here, to run once:
//initialize pins - Nothing
// start our seraial monitor
Serial.begin(9600); // use this to debug values
}
void loop() {
// put your main code here, to run repeatedly:
//now read/sense voltage from circuit | sensor/ read-command
IDontKnow = analogRead(A0); //read potentiometer signal from A0
Serial.println(IDontKnow); // print our vairable IDontKNow on a new line
//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(IDontKnow <= 512){
Serial.println("LEFT");
} else{
Serial.println("RIGHT");
}
//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
//map funciton
//map(var, range1v1, range1v2, range2v1, range2v2);
IDontKnowMapped = map(IDontKnow,0,1023,0,5);//divide by 100 - X.XX
IDontKnowMapped = map(IDontKnow,0,1023,7,-1000);
Serial.println(IDontKnowMapped);
//add a nice little 100ms delay for viewing purposes
delay(100);
}