Control Servo and LED Using Mouse (Assignment due Nov. 1, 2017)

Servo:

The first task was controlling a servo using the mouse. Since this exercise was almost 1:1 with what we did in class with the LED, I didn’t have any trouble with it. Instead of making the canvas size between 0 and 180 pixels, I used¬†map() on the Arduino side to scale the byte values received down to between 0 and 180. I also took this opportunity to try out Processing’s text features by labelling one side of the canvas as 0 degrees and the other as 180.

Arduino Code:

Processing Code:

LED:

This one was pretty fun to do, mostly because I like playing with LEDs. Once again, I revisited the principles of the dimmer and the servo control, this time paired with¬†mousePressed. If the mouse was in the bounds of my “off rectangle” while the button was pressed, I used Processing to send a “0” to Arduino which was stored in a variable the used in an if statement to turn the LED off. Similarly, if the mouse was in the bounds of my “on rectangle” while the button was pressed, I used Processing to send a “1” to Arduino which turned the LED on. I labelled the “off rectangle” using a circle and the “on rectangle” with a line to follow standard power symbols.

Arduino Code:

Processing Code:

Video:

Leave a Reply

Your email address will not be published. Required fields are marked *