Today was an introduction to the Arduinos. We were given an Arduino kit and asked to begin to work on a blink program. Following simple diagrams and reading through functions, we eventually completed simple tasks, such as making a LED light blink.
We were introduced to the various output pins and setting up our board using this function:
void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
}
We wrote this function to turn the light on and off in an infinite loop:
void loop() {
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(2000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
}
We experimented with different delays in order to make different patterns.
Day 1:
We began to work through an assignment sheet the went more into learning about functions and the variations of the blink LED program. One such program was blink without delay, which used a millisecond counter to determine when to blink:
This program used currentMillis to tell the LED when to blink through the Arduino pin.
We also worked with a servo, which we controlled using a potentiometer. We first controlled the position of the servo directly with the potentiometer (when we twisted the knob on the potentiometer, the servo would move in direct relation to the turn), and in the code below both the blink rate and servo position were controlled by the potentiometer.
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
void setup()
{
pinMode(8, OUTPUT);
}
void loop()
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
// val = map(val, 0, 1023, 0, 500); // scale it to use it with the servo (value between 0 and 180)
digitalWrite(8, HIGH); // turn the LED on (HIGH is the voltage level)
delay(val); // wait for a second
digitalWrite(8, LOW); // turn the LED off by making the voltage LOW
delay(val); // sets the servo position according to the scaled value
}
We also worked with a photocell which we used to control the position of the servo and the blink rate of the LED. Below is a test code where we were using the photocell readings to control the two:
An initial experimentation with just the LED and photocell:
After several attempts, here is our final code for the combination of the photocell, LED, and servo.
And photos and videos of our final setup:
Day 2:
We began with an introduction to functions by working with a morse code loop that used functions dot and dash to turn on the LED for different amounts of time in order to eventually convey a message.
Next, we began to work with the sciborgs which takes us to part two.





No comments:
Post a Comment