Experimen 2: Reading a potentiometer.
This experiment was made to test out a potentiometer.
Potentiometer is a knob that regulates the amount of electricity that goes through a circuit.
Code:
int sensorPin = 0;
int ledPin = 13;
void setup()
{ pinMode(ledPin, OUTPUT); }
void loop()
{ int sensorValue;
sensorValue = analogRead(sensorPin);
digitalWrite(ledPin, HIGH);
delay(sensorValue);
digitalWrite(ledPin, LOW);
delay(sensorValue); }
Code:
int sensorPin = 0; //the potentiometer was plugged to this pin, which was an analog, analog information in code goes straight through like a wave. Digital first gets transferred to 1 and 0's then turned into whatever you want so there will be an interval in between or the "glitch" can be explained because of this.
int ledPin = 13; //Back to the led pin we have used before.
void setup()
{ pinMode(ledPin, OUTPUT); } led pin is given a power output function
void loop() //loop starts blinking on and off on is high, off is low. Loop gives it the forever feeling.
{ int sensorValue; //this tells the sensor or meter to use the value it gives as the amount of power. We are using analog, therefore it is hands on action! remember the old radios turning knobs, that is what you were doing. Limiting and changing the amount of power it ran through it by turning the knob. This knob would change a dial that touched a metal on different parts. This is so cool!
sensorValue = analogRead(sensorPin);
digitalWrite(ledPin, HIGH); // tells the led to turn on
delay(sensorValue); // reads the value from the potentiometer to know the amount of delay per blink
digitalWrite(ledPin, LOW); // turns light off
delay(sensorValue); } // reads the value from the potentiometer to know the amount of delay per blink
Reflection

Comments
Post a Comment