aleksandra

Interface and Application Programming

Finally, this weeks assignment is about interface design and how can I interact with my board or how can my board be usefull for applications, like temperature sensor or force sensor. I decided to try out a mouse control application.

For an easy beginning I decided to use Arduino to create a servo programm and combine it with Processing for mouse control.

Adruino In the Arduino sequence below you can see Serial.available, and Serial.read. That means your microcontroller is waiting for input from serial device. The value (val) which is getting through this device will be the value information for the angle your servo has to get to. The baudrate has to be equal!

                    
                            
                            void loop() {
                                if (Serial.available()) {      
                                    val = Serial.read();          
                                } 
                                myservo.write(val);            
                                delay (15);               
                            }
                        
                        



Processing The following code part in Processing file is about the interactive window you can design. 'void draw' means that this window is drawing in a high frequency to actualize the position of the mouse control. The values in the simple brackets are about colors. If you have only one value it means you define the grey scale. If there are three values like 'fill' then it is red, green, blue. If you have four values it means shape design: first two values are x and y, the third and fourth values are about the shape. The last three lines are about mouse control and mouse position.

                    
                            
                            void draw() {   
                                background(255);  // Clear background 
                                fill(30,180,50);    // Set fill color 
                                ellipse(180, 220, 220, 220);      
                                float dif = mouseX-mx-25 ;
                                if (abs(dif) > 0.1) {
                                mx += dif/1.0;
                            }
                        
                        



The below part is about how the mouse position (it is a circle here) is translated into angle position.
                    
                            ellipse(mx+25, 220, 60, 60);               
                            int angle = int(map(mx, 75, 235,0,180));
                            myPort.write(angle); 
                            
                        
                        



plane plane

The upper picture is the Arduino sketch and beneath is the Processing sketch. First I wasn´t sure how to combine them and how it is possible to controll the board through a different sketch from a different program because in processing there is no pin declaration. But soon, I understood that for controlling I need the right port device and same baudrate. Thats all. Please see below my control layout:

plane



With an Arduino it is really easy to controll it because you just have to be plugged in via cable. Please see below the wiring with my own board:

Wiring the board with servo and serial device. After uploading the sketch to your board, you connect your servo to your pin you pointed out in your Arduino sketch and to vcc and gnd. Then you wire your board with your serial cable (TXD of your cable means RXD pin on your board).

plane







You can download here my first sketches for servo mouse control: Servo_sketch, Mouse_control