Use a mouse to control LEDs attached to an Arduino. This project uses the processing language to transmit the mouse coordinates to the Arduino, which then uses this information to turn on some LEDs. Please see the video below to see it in action.
Components Required for this project:
Arduino UNO
Breadboard
9 LEDs
9 x 330 ohm resistors
Wires to connect the circuit
USB connection cable: to connect the computer to the Arduino
A computer: to run the processing sketch, and to compile / upload the Arduino sketch
/* This program was created by ScottC on 9/5/2012 to receive serial signals from a computer to turn on/off 1-9 LEDs */
void setup() { // initialize the digital pins as an output. pinMode(2, OUTPUT); pinMode(3, OUTPUT); pinMode(4, OUTPUT); pinMode(5, OUTPUT); pinMode(6, OUTPUT); pinMode(7, OUTPUT); pinMode(8, OUTPUT); pinMode(9, OUTPUT); pinMode(10, OUTPUT); // Turn the Serial Protocol ON Serial.begin(9600); }
void loop() { byte byteRead;
/* check if data has been sent from the computer: */ if (Serial.available()) {
/* read the most recent byte */ byteRead = Serial.read(); //You have to subtract '0' from the read Byte to convert from text to a number. byteRead=byteRead-'0';
//Turn off all LEDS for(int i=2; i<11; i++){ digitalWrite(i, LOW); }
if(byteRead>0){ //Turn on the relevant LEDs for(int i=1; i<(byteRead+1); i++){ digitalWrite(i+1, HIGH); } } } }
//Open the serial port for communication with the Arduino //Make sure the COM port is correct myPort = new Serial(this, "COM6", 9600); myPort.bufferUntil('\n'); }
// Draw the Window on the computer screen void draw(){
// Fill canvas grey background( 100 );
// Set the stroke colour to white stroke(255);
// Draw a circle at the mouse location ellipse( nX, nY, 10, 10 );
//Draw Line from the top of the page to the bottom of the page //in line with the mouse. line(nX,0,nX,height); }
// Get the new mouse location and send it to the arduino void mouseMoved(){ nX = mouseX; nY = mouseY;
//map the mouse x coordinates to the LEDs on the Arduino. new_sX=(int)map(nX,0,800,0,10);
if(new_sX==old_sX){ //do nothing } else { //only send values to the Arduino when the new X coordinates are different. old_sX = new_sX; myPort.write(""+new_sX); } }
Have you ever wondered if there was a way to store and retrieve data from a USB stick with an Arduino UNO? Most people choose SD cards to store their project data, but you may be surprised there IS a way! IC Station have a nice little module which allows you store and retrieve your Arduino (or other MCU) project data to a USB stick. I am not too sure why USB storage is not widely used in Arduino projects? These modules are not expensive, they have been around for quite a while, and are relatively simple to use. You do not need any libraries to get them to work, however, I must say that documentation for this module is not that easy to find. This site and this document proved to be very useful in my endevour to get this module working, and I hope my tutorial below will help you get started and bridge some of the information gaps. The...
Guest Post Disclaimer This is a guest post by the EasyEDA team. I would like to thank EasyEDA for providing this tutorial for everyone to enjoy. All information within this post was provided by EasyEDA. Description None of us could deny the fact that we would love with to play with LED’s and lighting stuff. I love to play with LED’s and create attractive lighting effects. This project was a result of such an attempt where I created a stunning RGB light effect using the popular development platform Arduino Nano. Let’s see the circuit, code and instruction on building this project: Parts Required: An EasyEDA account (free) Arduino Nano (or compatible board) LED strip Dupont wire connectors Custom control board Image source: EasyEDA Ardui...
FIVE MINUTE TUTORIAL Project Description: Sending Hex values to an Arduino UNO This simple tutorial will show you how to send Hexadecimal values from a computer to an Arduino Uno. The "Processing" programming language will be used to send the HEX values from the computer when a mouse button is pressed. The Arduino will use these values to adjust the brightness of an LED. Learning Objectives To Send Hexadecimal (Hex) values from a computer to the Arduino Trigger an action based on the press of a mouse button Learn to create a simple Computer to Arduino interface Use Arduino's PWM capabilities to adjust brightness of an LED Learn to use Arduino's analogWrite() function Create a simple LED circuit...
Comments
Post a Comment