Created
November 8, 2013 23:56
-
-
Save antonva/7379533 to your computer and use it in GitHub Desktop.
arduino code for workning mouse.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SerialMouse sketch | |
const int left_button = 2; | |
const int right_button = 4; | |
const int x_pin = 4; // analog pins for pots | |
const int y_pin = 5; | |
void setup() | |
{ | |
Serial.begin(9600); | |
pinMode(right_button, INPUT); | |
pinMode(left_button, INPUT); | |
digitalWrite(right_button, HIGH); | |
digitalWrite(left_button, HIGH); | |
} | |
void loop() | |
{ | |
// Deilt með 4 til að fa 0 - 255 | |
int x = (analogRead(x_pin)) / 4; | |
int y = (analogRead(y_pin)) / 4; | |
//Prentum data | |
Serial.print("Data,"); | |
Serial.print(x,DEC); | |
Serial.print(","); | |
Serial.print(y,DEC); | |
Serial.print(","); | |
//Vinstri takkinn. | |
if(digitalRead(left_button) == LOW) | |
{ | |
Serial.print(1); | |
} | |
else | |
{ | |
Serial.print(0); | |
} | |
Serial.print(","); | |
//Haegri takkinn. | |
if(digitalRead(right_button) == LOW) | |
{ | |
Serial.print(1); | |
} | |
else | |
{ | |
Serial.print(0); | |
} | |
Serial.println(","); | |
delay(50); //Sendum gogn 10x a sekundu. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment