Components and supplies
Annikken Andee for Android
Arduino UNO
Project description
Code
Code snippet #4
arduino
1void loop() 2{ 3 if( btnCustomPosition.isPressed() ) 4 { 5 memset(userPos, 0x00, 4); // Empty the contents of the string before receiving user input 6 btnCustomPosition.ack(); // Acknowledge button press or else phone will be left waiting 7 btnCustomPosition.getKeyboardMessage(userPos); // Display keyboard and store input into userInput 8 9 newPosition = atoi(userPos); // Convert string value to integer value 10 11 // Tell Arduino x Andee what to do if user keys in ridiculous values 12 if(newPosition < 0) newPosition = 0; 13 if(newPosition > 180) newPosition = 180; 14 15 currentPosition = newPosition; 16 // This is how you do a quick turn 17 theServo.write(currentPosition); // Turn servo to new position 18 displaybox.setData(currentPosition); // Update new position 19 } 20 21 if( btnTurnLeft.getButtonPressCount() > 0 ) // As long as left button is pressed 22 { 23 btnTurnLeft.ack(); // Acknowledge button press or else phone will be left waiting 24 newPosition = currentPosition - turnResolution; // Set new position 25 if(newPosition < 0) newPosition = 0; // Set to 0 if new position goes below 0 26 27 // This is how you do a slow turn: 28 for(currentPosition; currentPosition > newPosition; currentPosition--) 29 { 30 theServo.write(currentPosition); 31 displaybox.setData(currentPosition); // Update servo position on screen as it turns 32 displaybox.update(); 33 delay(15); // You can change the delay value. Larger value means slower turns 34 // Do not set your delay to 0 when you're doing this. You run the possibility of 35 // damaging the servo. Or you might just make it become more cranky. 36 } 37 } 38 39 if( btnTurnRight.getButtonPressCount() > 0 ) // As long as right button is pressed 40 { 41 btnTurnRight.ack(); // Acknowledge button press or else phone will be left waiting 42 newPosition = currentPosition + turnResolution; // Set new position 43 if(newPosition > 180) newPosition = 180; // Set to 180 if new position goes above 180 44 for(currentPosition; currentPosition < newPosition; currentPosition++) 45 { 46 theServo.write(currentPosition); 47 displaybox.setData(currentPosition); // Update servo position on screen as it turns 48 displaybox.update(); 49 delay(15); // You can change the delay value. Larger value means slower turns 50 } 51 } 52 53 btnTurnLeft.update(); // Always remember to update so that new content will be displayed 54 btnTurnRight.update(); 55 btnCustomPosition.update(); 56 displaybox.update(); 57 58 delay(500); // Always leave a short delay for Bluetooth communication 59}
Code snippet #1
arduino
1#include <SPI.h> 2#include <Andee.h> 3#include <Servo.h> // You need this for your servos to work 4 5AndeeHelper btnTurnLeft; 6AndeeHelper btnTurnRight; 7AndeeHelper btnCustomPosition; 8AndeeHelper displaybox; 9 10Servo theServo; // Declare a servo 11 12char userPos[4]; 13int currentPosition; // Stores current position of servo (from 0 to 180) 14int newPosition; 15int turnResolution = 10; // Servo turns by 20 every time left/right turn button is pressed 16const int servoPin = 9; // Servo connected to pin 9
Code snippet #5
arduino
1#include <SPI.h> 2#include <Andee.h> 3#include <Servo.h> // You need this for your servos to work 4 5AndeeHelper btnTurnLeft; 6AndeeHelper btnTurnRight; 7AndeeHelper btnCustomPosition; 8AndeeHelper displaybox; 9 10Servo theServo; // Declare a servo 11 12char userPos[4]; 13int currentPosition; // Stores current position of servo (from 0 to 180) 14int newPosition; 15int turnResolution = 10; // Servo turns by 20 every time left/right turn button is pressed 16const int servoPin = 9; // Servo connected to pin 9 17 18void setup() 19{ 20 Andee.begin(); // Setup communication between Annikken Andee and Arduino 21 Andee.clear(); // Clear the screen of any previous displays 22 currentPosition = 0; // Initialise position to 0 23 theServo.attach(servoPin); // Tell Arduino which pin the servo is connected to 24 theServo.write(currentPosition); // Set servo to position 0 25 setInitialData(); // Define object types and their appearance 26} 27 28void setInitialData() 29{ 30 btnTurnLeft.setId(0); 31 btnTurnLeft.setType(BUTTON_IN); 32 btnTurnLeft.setLocation(0,0,HALF); 33 btnTurnLeft.setTitle("Turn Left"); 34 btnTurnLeft.requireAck(false); // You need this line to allow for multiple button presses 35 36 btnTurnRight.setId(1); 37 btnTurnRight.setType(BUTTON_IN); 38 btnTurnRight.setLocation(0,1,HALF); 39 btnTurnRight.setTitle("Turn Right"); 40 btnTurnRight.requireAck(false); // You need this line to allow for multiple button presses 41 42 btnCustomPosition.setId(2); 43 btnCustomPosition.setType(KEYBOARD_IN); // Sets object as a text input button 44 btnCustomPosition.setLocation(1,0,FULL); 45 btnCustomPosition.setTitle("Quickly Go to Custom Position (0 - 180)"); 46 btnCustomPosition.setKeyboardType(ANDEE_NUMERIC_A); 47 48 displaybox.setId(3); 49 displaybox.setType(DATA_OUT); // Sets object as a text input button 50 displaybox.setLocation(2,0,FULL); 51 displaybox.setTitle("Current Position"); 52 displaybox.setData(0); 53} 54 55void loop() 56{ 57 if( btnCustomPosition.isPressed() ) 58 { 59 memset(userPos, 0x00, 4); // Empty the contents of the string before receiving user input 60 btnCustomPosition.ack(); // Acknowledge button press or else phone will be left waiting 61 btnCustomPosition.getKeyboardMessage(userPos); // Display keyboard and store input into userInput 62 63 newPosition = atoi(userPos); // Convert string value to integer value 64 65 // Tell Arduino x Andee what to do if user keys in ridiculous values 66 if(newPosition < 0) newPosition = 0; 67 if(newPosition > 180) newPosition = 180; 68 69 currentPosition = newPosition; 70 // This is how you do a quick turn 71 theServo.write(currentPosition); // Turn servo to new position 72 displaybox.setData(currentPosition); // Update new position 73 } 74 75 if( btnTurnLeft.getButtonPressCount() > 0 ) // As long as left button is pressed 76 { 77 btnTurnLeft.ack(); // Acknowledge button press or else phone will be left waiting 78 newPosition = currentPosition - turnResolution; // Set new position 79 if(newPosition < 0) newPosition = 0; // Set to 0 if new position goes below 0 80 81 // This is how you do a slow turn: 82 for(currentPosition; currentPosition > newPosition; currentPosition--) 83 { 84 theServo.write(currentPosition); 85 displaybox.setData(currentPosition); // Update servo position on screen as it turns 86 displaybox.update(); 87 delay(15); // You can change the delay value. Larger value means slower turns 88 // Do not set your delay to 0 when you're doing this. You run the possibility of 89 // damaging the servo. Or you might just make it become more cranky. 90 } 91 } 92 93 if( btnTurnRight.getButtonPressCount() > 0 ) // As long as right button is pressed 94 { 95 btnTurnRight.ack(); // Acknowledge button press or else phone will be left waiting 96 newPosition = currentPosition + turnResolution; // Set new position 97 if(newPosition > 180) newPosition = 180; // Set to 180 if new position goes above 180 98 for(currentPosition; currentPosition < newPosition; currentPosition++) 99 { 100 theServo.write(currentPosition); 101 displaybox.setData(currentPosition); // Update servo position on screen as it turns 102 displaybox.update(); 103 delay(15); // You can change the delay value. Larger value means slower turns 104 } 105 } 106 107 btnTurnLeft.update(); // Always remember to update so that new content will be displayed 108 btnTurnRight.update(); 109 btnCustomPosition.update(); 110 displaybox.update(); 111 112 delay(500); // Always leave a short delay for Bluetooth communication 113}
Code snippet #2
arduino
1void setup() 2{ 3 Andee.begin(); // Setup communication between Annikken Andee and Arduino 4 Andee.clear(); // Clear the screen of any previous displays 5 currentPosition = 0; // Initialise position to 0 6 theServo.attach(servoPin); // Tell Arduino which pin the servo is connected to 7 theServo.write(currentPosition); // Set servo to position 0 8 setInitialData(); // Define object types and their appearance 9}
Code snippet #2
arduino
1void setup() 2{ 3 Andee.begin(); // Setup communication between Annikken Andee and Arduino 4 Andee.clear(); // Clear the screen of any previous displays 5 currentPosition = 0; // Initialise position to 0 6 theServo.attach(servoPin); // Tell Arduino which pin the servo is connected to 7 theServo.write(currentPosition); // Set servo to position 0 8 setInitialData(); // Define object types and their appearance 9}
Code snippet #3
arduino
1void setInitialData() 2{ 3 btnTurnLeft.setId(0); 4 btnTurnLeft.setType(BUTTON_IN); 5 btnTurnLeft.setLocation(0,0,HALF); 6 btnTurnLeft.setTitle("Turn Left"); 7 btnTurnLeft.requireAck(false); // You need this line to allow for multiple button presses 8 9 btnTurnRight.setId(1); 10 btnTurnRight.setType(BUTTON_IN); 11 btnTurnRight.setLocation(0,1,HALF); 12 btnTurnRight.setTitle("Turn Right"); 13 btnTurnRight.requireAck(false); // You need this line to allow for multiple button presses 14 15 btnCustomPosition.setId(2); 16 btnCustomPosition.setType(KEYBOARD_IN); // Sets object as a text input button 17 btnCustomPosition.setLocation(1,0,FULL); 18 btnCustomPosition.setTitle("Quickly Go to Custom Position (0 - 180)"); 19 btnCustomPosition.setKeyboardType(ANDEE_NUMERIC_A); 20 21 displaybox.setId(3); 22 displaybox.setType(DATA_OUT); // Sets object as a text input button 23 displaybox.setLocation(2,0,FULL); 24 displaybox.setTitle("Current Position"); 25 displaybox.setData(0); 26}
Code snippet #3
arduino
1void setInitialData() 2{ 3 btnTurnLeft.setId(0); 4 btnTurnLeft.setType(BUTTON_IN); 5 6 btnTurnLeft.setLocation(0,0,HALF); 7 btnTurnLeft.setTitle("Turn Left"); 8 9 btnTurnLeft.requireAck(false); // You need this line to allow for multiple button 10 presses 11 12 btnTurnRight.setId(1); 13 btnTurnRight.setType(BUTTON_IN); 14 15 btnTurnRight.setLocation(0,1,HALF); 16 btnTurnRight.setTitle("Turn Right"); 17 18 btnTurnRight.requireAck(false); // You need this line to allow for multiple button 19 presses 20 21 btnCustomPosition.setId(2); 22 btnCustomPosition.setType(KEYBOARD_IN); 23 // Sets object as a text input button 24 btnCustomPosition.setLocation(1,0,FULL); 25 26 btnCustomPosition.setTitle("Quickly Go to Custom Position (0 - 180)"); 27 btnCustomPosition.setKeyboardType(ANDEE_NUMERIC_A); 28 29 30 displaybox.setId(3); 31 displaybox.setType(DATA_OUT); // Sets object 32 as a text input button 33 displaybox.setLocation(2,0,FULL); 34 displaybox.setTitle("Current 35 Position"); 36 displaybox.setData(0); 37}
Code snippet #4
arduino
1void loop() 2{ 3 if( btnCustomPosition.isPressed() ) 4 { 5 memset(userPos, 0x00, 4); // Empty the contents of the string before receiving user input 6 btnCustomPosition.ack(); // Acknowledge button press or else phone will be left waiting 7 btnCustomPosition.getKeyboardMessage(userPos); // Display keyboard and store input into userInput 8 9 newPosition = atoi(userPos); // Convert string value to integer value 10 11 // Tell Arduino x Andee what to do if user keys in ridiculous values 12 if(newPosition < 0) newPosition = 0; 13 if(newPosition > 180) newPosition = 180; 14 15 currentPosition = newPosition; 16 // This is how you do a quick turn 17 theServo.write(currentPosition); // Turn servo to new position 18 displaybox.setData(currentPosition); // Update new position 19 } 20 21 if( btnTurnLeft.getButtonPressCount() > 0 ) // As long as left button is pressed 22 { 23 btnTurnLeft.ack(); // Acknowledge button press or else phone will be left waiting 24 newPosition = currentPosition - turnResolution; // Set new position 25 if(newPosition < 0) newPosition = 0; // Set to 0 if new position goes below 0 26 27 // This is how you do a slow turn: 28 for(currentPosition; currentPosition > newPosition; currentPosition--) 29 { 30 theServo.write(currentPosition); 31 displaybox.setData(currentPosition); // Update servo position on screen as it turns 32 displaybox.update(); 33 delay(15); // You can change the delay value. Larger value means slower turns 34 // Do not set your delay to 0 when you're doing this. You run the possibility of 35 // damaging the servo. Or you might just make it become more cranky. 36 } 37 } 38 39 if( btnTurnRight.getButtonPressCount() > 0 ) // As long as right button is pressed 40 { 41 btnTurnRight.ack(); // Acknowledge button press or else phone will be left waiting 42 newPosition = currentPosition + turnResolution; // Set new position 43 if(newPosition > 180) newPosition = 180; // Set to 180 if new position goes above 180 44 for(currentPosition; currentPosition < newPosition; currentPosition++) 45 { 46 theServo.write(currentPosition); 47 displaybox.setData(currentPosition); // Update servo position on screen as it turns 48 displaybox.update(); 49 delay(15); // You can change the delay value. Larger value means slower turns 50 } 51 } 52 53 btnTurnLeft.update(); // Always remember to update so that new content will be displayed 54 btnTurnRight.update(); 55 btnCustomPosition.update(); 56 displaybox.update(); 57 58 delay(500); // Always leave a short delay for Bluetooth communication 59}
Code snippet #1
arduino
1#include <SPI.h> 2#include <Andee.h> 3#include <Servo.h> // You need this for your servos to work 4 5AndeeHelper btnTurnLeft; 6AndeeHelper btnTurnRight; 7AndeeHelper btnCustomPosition; 8AndeeHelper displaybox; 9 10Servo theServo; // Declare a servo 11 12char userPos[4]; 13int currentPosition; // Stores current position of servo (from 0 to 180) 14int newPosition; 15int turnResolution = 10; // Servo turns by 20 every time left/right turn button is pressed 16const int servoPin = 9; // Servo connected to pin 9
Comments
Only logged in users can leave comments
Arduino_Scuola
0 Followers
•0 Projects
Table of contents
Intro
1
0