Skip to content

Instantly share code, notes, and snippets.

@antonva
Created November 8, 2013 23:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonva/7379533 to your computer and use it in GitHub Desktop.
Save antonva/7379533 to your computer and use it in GitHub Desktop.
arduino code for workning mouse.
// 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