TechnicalEngineer
Created September 14, 2018 © GPL3+

Insight into Arduino: Beginner's Guide

This article about Arduino is an introductory explanation regarding its configuration, types, and applications along with the installation.

BeginnerProtip15
Insight into Arduino: Beginner's Guide

Story

Read more

Schematics

Pin Configuration Of ATmega8 IC For Arduino

Code

Demonstration on how to wirelessly send path information data of the movement of a PS2 mouse in X

C Header File
 Demonstration on how to wirelessly send path information data of the 

 movement of a PS2 mouse in X direction using Xbee


 The circuit:

 LCD:

 * LCD RS pin to digital pin 12

 * LCD Enable pin to digital pin 11

 * LCD D4 pin to digital pin 7

 * LCD D5 pin to digital pin 6

 * LCD D6 pin to digital pin 5

 * LCD D7 pin to digital pin 4

 * LCD R/W pin to ground

 * 10K resistor:

 * ends to +5V and ground

 * wiper to LCD pin 3

 * LED anode attached to digital output 9

 * LED cathode attached to ground through a 1K resistor


 MOUSE:

 DATA PIN TO PIN NUMBER 8

 CLOCK PIN TO PIN NUMBER 3


 XBEE:

 RX PIN OF XBEE TO TX0 PIN OF ARDUINO

 SHORT THE GROUND PINS OF ARDUINO AND XBEE

============================== EG LABS ===================================*/


#include "PS2Mouse.h"

#define MOUSE_DATA 8

#define MOUSE_CLOCK 3

// include the library code:

#include <LiquidCrystal.h>


// initialize the library with the numbers of the interface pins

LiquidCrystal lcd(12, 11, 7, 6, 5, 4);


// initialize the mouse library

PS2Mouse mouse(MOUSE_CLOCK, MOUSE_DATA, STREAM);


int i;

int x_acc = 0;

int pos = 0;

int data[2];

  

void setup()

{

  pinMode(9, OUTPUT);  

  

  // set up the lcd's number of columns and rows: 

  lcd.begin(16, 2);

  lcd.print("ENGINEERS GARAGE");

  lcd.setCursor(0, 1);

  lcd.print("  MOUSE to XBEE ");

  delay(2000);

  digitalWrite(9, HIGH);

  

  Serial.begin(9600);

  

  mouse.initialize();                        // initialize the PS2 mouse connected with the Arduino

}


void loop()

{

  x_acc = 0;

  

  for(i = 0; i < 100; i ++)

  {

      do

      {

        mouse.report(data);                         // get data from the mouse

      }while(data[1] == 0); 

      x_acc += data[1];

  }

  

  //=== get the average movement in the x direction ===//

  x_acc = x_acc / 200;

  x_acc = x_acc + pos;

  

  if(x_acc > 100)

    x_acc = 100;

  else;

  //=== get the average movement in the x direction ===// 

  

  Serial.println();

  for(i = 0; i < (100 + x_acc); i ++)

    Serial.print(" ");

  Serial.print("*");

  

  pos = x_acc;

  

}

 

Credits

TechnicalEngineer
4 projects • 51 followers
Contact

Comments

Please log in or sign up to comment.