Homework due Wednesday November 1: Control servo and led with mouse using Arduino and Processing

  1. Control a servo motor connected to Arduino using your mouse in Processing

This task is quite similar to the Dimmer example, so I only need to change some code in the Dimmer example, such as the width of the canvas. Also, I draw left and right arrows to indicate the direction of the servo in Processing.

Arduino code:  

Processing code

Result

2. Control an LED connected to your Arduino using two rectangles in Processing

For this task, I use mouseClicked() to send the 1 or 0 to turn the led on or off. If the position of the mouse is inside the on button, ‘1’ is sent to the serial port. If the position of the mouse is inside the off button, ‘0’ is sent to the serial port. 

Arduino code 

 

Processing code: 

 

Result

Leave a Reply

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