/* Reads a T000030 Joystick Module Analog Sensor connected to I0 and I1, then set the brightness of two T010111 LED Module connected on O0 and O1 with the values. Also prints the results to the serial monitor. http://www.tinkerkit.com/joystick/ http://www.tinkerkit.com/led-green-10mm/ created 7 dec 2010 by Davide Gomba modified on Dec 2011 by Federico Vanzati modified on Jun 2013 by Matteo Loglio This example code is in the public domain. */ // include the TinkerKit library #include #include Servo LeftServo; Servo RightServo; int xpos; int ypos; TKJoystick joystick(A2, A3); // creating the object 'joystick' that belongs to the 'TKJoystick' class // and giving the values to the desired input pins // creating the objects 'xLed' & 'yLed' that both belongs to the 'TKLed' class // and giving the values to the desired output pins int x = 0; // a variable for the Joystick's x value int y = 0; // a variable for the Joystick's y value void setup() { // initialize serial communications at 9600 bps LeftServo.attach(6); RightServo.attach(5); Serial.begin(9600); xpos = 95; ypos = 95; Serial.print("Olen setupis"); } void loop() { Serial.print(xpos); Serial.print("\n "); // read the both joystick axis values: //pos = 0; x = joystick.readX(); y = joystick.readY(); // set the leds brightness // print the results to the serial monitor: Serial.print("\n Joystick X = \n" ); Serial.print(x); Serial.print("\n Joystick Y = \n" ); Serial.print(y); Serial.print("\n "); if(y>500 && y<600 ) { LeftServo.write(xpos = 95); RightServo.write(ypos = 95); delay(25); } if(y>=600 ) { Serial.print("edasi \n "); LeftServo.write(xpos = 180); RightServo.write(ypos = 1); delay(25); } if (y<=500) { Serial.print("tagasi \n "); LeftServo.write(xpos = 1); RightServo.write(ypos = 180); delay(25); } // wait 10 milliseconds before the next loop delay(100); }