Your Arduino isn't going to always be attached to a computer so its a good idea to have some other form of visual feedback besides the serial monitor. This is where your LCD comes in handy. It makes your project look cooler and allows you to debug and get some feedback from your program while disconnected from your computer.
I really should look into getting a back lit LCD, cooler looking AND easier to read |
Thumb joystick plus breakout board |
Wow that microphone is sensitive... my nose is stuffy, big whoop wanna fight about it?
Here's the code I used from the video:
// Noah Stahl
// http://arduinomega.blogspot.com
// Arduino Mega 2560
//This sketch continuously measures the vertical and horizontal
//positions of a thumb joystick and displays the results on an LCD.
//This code assumes that you are using a 20x2 LCD with 4-bit data
// LCD Vss(1) to GND
// LCD Vdd(2) to +5V
// LCD Vo (3) to +5V (contrast control)
// LCD RS (4) to digital pin 53
// LCD R/W(5) to GND
// LCD EN (6) to digital pin 52
// LCD D4 (7) to digital pin 50
// LCD D5 (8) to digital pin 49
// LCD D6 (9) to digital pin 48
// LCD D7 (10)to digital pin 47
#include <LiquidCrystal.h>
// Specify the numbers of the LCD pins on the Arduino
LiquidCrystal lcd(53, 52, 50, 49, 48, 47); // RS, EN, D4, D5, D6, D7
void setup()
{
lcd.begin(20, 2); // Number of columns and rows on the LCD
lcd.clear();
lcd.println("ArduinoMega Blagspot");
lcd.setCursor(0,1);
lcd.println("Thumb Joystick Test ");
delay(5000);
lcd.clear();
}
void loop()
{
lcd.setCursor(0,0);
lcd.print("Horizontal: ");
lcd.print(analogRead(1)); // HORZ pin connected to A1
lcd.setCursor(0,1);
lcd.print(" Vertical: ");
lcd.print(analogRead(0)); // VERT pin connected to A0
delay(100); // Prevents LCD from updating too quickly
lcd.clear();
}
// http://arduinomega.blogspot.com
// Arduino Mega 2560
//This sketch continuously measures the vertical and horizontal
//positions of a thumb joystick and displays the results on an LCD.
//This code assumes that you are using a 20x2 LCD with 4-bit data
// LCD Vss(1) to GND
// LCD Vdd(2) to +5V
// LCD Vo (3) to +5V (contrast control)
// LCD RS (4) to digital pin 53
// LCD R/W(5) to GND
// LCD EN (6) to digital pin 52
// LCD D4 (7) to digital pin 50
// LCD D5 (8) to digital pin 49
// LCD D6 (9) to digital pin 48
// LCD D7 (10)to digital pin 47
#include <LiquidCrystal.h>
// Specify the numbers of the LCD pins on the Arduino
LiquidCrystal lcd(53, 52, 50, 49, 48, 47); // RS, EN, D4, D5, D6, D7
void setup()
{
lcd.begin(20, 2); // Number of columns and rows on the LCD
lcd.clear();
lcd.println("ArduinoMega Blagspot");
lcd.setCursor(0,1);
lcd.println("Thumb Joystick Test ");
delay(5000);
lcd.clear();
}
void loop()
{
lcd.setCursor(0,0);
lcd.print("Horizontal: ");
lcd.print(analogRead(1)); // HORZ pin connected to A1
lcd.setCursor(0,1);
lcd.print(" Vertical: ");
lcd.print(analogRead(0)); // VERT pin connected to A0
delay(100); // Prevents LCD from updating too quickly
lcd.clear();
}
You might have noticed that the horizontal centers at 525 instead of 512. Since it is consistent you could easily adapt your code to accommodate this.
The analog values will also max/minimize out before the joystick actually reaches its full range of motion. These dead spots are close enough to the edges that it shouldn't be a problem for your project. There is also an extra pin on the breakout board for the built in tactile switch which I didn't utilize in this demo. For less than $4, can you really complain? (Don't answer that...) Once I get around to setting up my Xbees with the Arduino, this would be perfect for a remote control. For another update though!
yo man im sitting here doing the same thing right now haha....im trying to figure out if there is any real simple games i could code...got any ideas?
ReplyDeletebtw im using a serial lcd...so much simpler bro
ReplyDelete