Pages

Sunday, March 8, 2015

Arduino Day 2

3/6/2015: Knob and Sweep

After demonstrating our 4 red LED lights to the class, we got started with a modifying new default programs: sweep & knob, that control a servo motor in different ways.

Part 1: Sweep 
The default sweep program makes the motor move back and forth 180 degrees, taking 15 milliseconds to reach each new degree.

Task: to modify sweep so that it would go faster and slower as it rotated back and forth
Fiddling with syntax and the for loops again, we managed to make our servo motor speed up in the first 90 degrees going forward, slow down for the next 90 degrees after (180 degrees total), and then speed up the first 90 degrees backwards, and finally speeding up the rest of the 90 degrees backwards.

Part 2: Knob 

The knob works different with the servo motor. In this program, since the servo motor can only turn 180 degrees, the loop readjusts the range of the potentiometer, which has a value between 0 to 1023. Then, it reads every value of the knob that we turn, and translates that value into a degree on the motor, taken 15 milliseconds to reach that degree. So as we turned the knob, we were also turning the motor.

Task: to modify knob so that the higher the value in the potentiometer, the faster the LED blinks

We had much difficult with figuring out the modification for this program. Should we use for loops? Should we use if statements? We understood  the initial knob function, but perhaps not enough? We knew that we needed to initialize the pin, initialize the potentiometer, but we were quite confused as to how we would get the program to make our LED blink. Referring back to our "Blink Without Delay" program, we had tried using for loops and other statements to help us, but that wasn't what we needed.

With Amy's help, we got our thoughts reorganized again.
1) initiate ledPin (pinMode, LED attached to pin 8)
2) initiate potentiometer (analogRead)
3) make LED light blink on
4) delay the "blink on" according to val
5) make LED light blink off
5) delay "blink off" according to val 

  
We were almost there! The program was done, but the wiring wasn't exactly correct yet. We had attached to the potentiometer with pin 8 and the LED light, but they were supposed to be attached separately, working together only the Arduino board as its connector/mastermind. 

Next up:
The photocell! We'll be modifying a photocell program so that we will:
1) fix scaling in program (calibrating)
2) make photocell control blink rate & servo position

Small Reflection: It would have saved us more time if we had thought about achieving the main function of the task than about the different ways we could have done it. I kept going through versions of for loops and if statements through my head, and it would have been nice to remember that the program itself is already in a loop, and that the blink off/on program was very similar to the first programs that modified. In our upcoming project, I hope we can have a clear mindset about the tasks that the photocell will accomplish, and will efficiently write code to achieve that purpose.

2 comments:

  1. I liked your post a lot! I thought that making the font/color of your tasks different from the rest of the page made it especially clear on what you were trying to accomplish. I liked how for the Knob & Potentiometer program you listed out your subgoals before showing us the programming commands that you needed. Great work on the Arduino, and also at the CSA culture show!

    ReplyDelete
  2. How and where would you modify your program so that you don't use the if statements?

    ReplyDelete