Wednesday, June 1, 2016

Arduino part 2

This blog posting continues the earlier blog posting that introduced Arduino.  
For some reason, I actually bothered take screen shots of my code, which means, the syntax is highlighted and will look nice, unlike my other blog postings, where I just copy past the code within a <code> </code> tags 

In this session, we tried to change use the potentiometer to change the blink speed.
We have the wait time as a factor of the potentiometer value.  




We also tried to us light readings from a light encoder.  depending on how light the light sensor registered, we had it light up different LEDs. 
This is the setup:
This is the result of my code




We also tried to use a small switch to turn the LED on and off. 

This is the code.  We used a boolean value to register whether the button has been pressed or not and based on that, value it determines if the light is on or not.
setup:

demo:



this is the sweep code that I downloaded form the Arduino examples. As you can see, the code makes the servo go back and forth between a position of -180 to a position of +180 degrees. 



Now if we wanted to change our code so that the servo only goes betwene 60 and 120 degrees, then one way that we did it was by mapping the range of values that can be outputted through the potentiometer readings to be between 60 and 120.   This is a short way through the code of limiting the scope of radial movement for the servo.  This mapping of potentiometer to output, I took from the earlier introduction to Arduino. 

Setup:
Here is a cool video of using the potentiometer to determine the angle of the servo.