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...
Introduction Nextion is a programmable human machine interface (HMI) that can be customized and designed to simplify the interaction between you and your project. This Nextion Enhanced module (NX4827K043) with a resistive touch screen display, has some additional features not seen in previous traditional versions of the Nextion series. A built in real time clock (RTC) Accessible flash memory (32MB) GPIO functionality Faster clock speed Before you connect the Nextion Enhanced module to your project, you need to design your interface with the free Nextion Editor. The editor can be downloaded here. In this project, I will be designing a simple dynamic interface, which will allow me to interact with a stepper motor in two different ways. The first interface will let me control the direction and speed of the stepper motor through the use of a simple GUI. I will have left and right arrows for the direction, and up and down arrows for the speed. I will also map the Expansion board...
PART THREE If you happened to land on this page and missed PART ONE , and PART TWO , I would advise you go back and read those sections first. This is what you'll find in partone : Downloading and setting up the Android SDK Downloading the Processing IDE Setting up and preparing the Android device Running through a couple of Processing/Android sketches on an Andoid phone. This is what you will find in part two : Introducing Toasts (display messages) Looking out for BluetoothDevices using BroadcastReceivers Getting useful information from a discovered Bluetooth device Connecting to a Bluetooth Device An Arduino Bluetooth Sketch that can be used in this tutorial InputStream and OutputStream We will now borrow some code from the Android developers site to help us to establish communication between the Android phone and the Bluetooth shield on the Arduino. By this stage we have already scanned and discovered the bluetooth device and made a successful connection. We now need to create ...
Comments
Post a Comment