Hey guys, here's a link of an analog sensor average code from ITP's PhyComp website
[One Sensor Avg]
« September 2008 | Main | November 2008 »
Hey guys, here's a link of an analog sensor average code from ITP's PhyComp website
[One Sensor Avg]
Posted at 10:11 PM in Jennifer Dopazo | Permalink | Comments (0) | TrackBack (0)
LED Switch with IR Sensor from Katrina Bekessy on Vimeo.
I tried Matt's code and it worked well, but what you see in the video is my less sophisticated code at work which you can see here:
int irPin = 3; // IR sensor is read from pin 3
int irVal = 0; // hold the values read from the IR sensor
int orngPin = 9; // Orange LED, connected to digital pin 9
int bluPin = 10; // Blue LED, connected to digital pin 10
int grnPin = 11; // Green LED, connected to digital pin 11
void setup()
{
pinMode(orngPin, OUTPUT); // sets the pins as output
pinMode(bluPin, OUTPUT);
pinMode(grnPin, OUTPUT);
Serial.begin(9600); //see what the heck my IR sensor is reading
}
// Main program
void loop()
{
irVal = analogRead(irPin);
if (irVal>=200) //when you're closest to the sensor
{
digitalWrite(grnPin, HIGH);
digitalWrite(bluPin, LOW);
digitalWrite(orngPin, LOW);
}
else if (irVal>= 75 && irVal<=200) //middle range of sensor
{
digitalWrite(grnPin, LOW);
digitalWrite(bluPin, HIGH);
digitalWrite(orngPin, LOW);
}
else if (irVal<75) //when you're the furthest away
{
digitalWrite(grnPin, LOW);
digitalWrite(bluPin, LOW);
digitalWrite(orngPin, HIGH);
}
Serial.print(irVal);
Serial.println();
}
Posted at 07:44 PM in Code, Katrina Bekessy | Permalink | Comments (0) | TrackBack (0)
Posted at 05:59 PM in Maze Hsiao | Permalink | Comments (0) | TrackBack (0)
IR sensor + 3 color LEDs from maze on Vimeo.
I didn't use the average code, actually I didn't know there's an average code until Yury mentioned about it.
Somehow my LEDs wouldn't flicker a lot.
So here is my code. It is quite simple.
Basically I just change the on and off status of each LED in different ranges.
------------------------------------------------------------------------------
/*
*New Arduino hooked-up to 3 different Super-Bright LEDs.
*Program the 3 LEDs to turn on/off individually depending on distance of hand.
*Tzumei M. Hsiao
*/
// Analog pin settings
int irIn = 3; // the IR sensor connected to the analog pin 3
// Digital pin settings
int redLED = 9; // LEDs connected to digital pins 9, 10 and 11
int blueLED = 10; // (Connect cathodes to digital ground)
int greenLED = 11;
// Values
int irVal = 0; // the variable to store the input from the IR sensor
int redVal = 0; // the variable to store the value of red LED
int greenVal = 0; // the variable to store the value of green LED
int blueVal = 0; // the variable to store the value of blue LED
// Variables for comparing values between loops
int i = 0; // Loop counter
int wait = (1000); // Delay between most recent pot adjustment and output
int sens = 3; // Sensitivity threshold, to prevent small changes in
// IR sensor values from triggering false reporting
// FLAGS
int PRINT = 1; // Set to 1 to output values
void setup()
{
pinMode(redLED, OUTPUT); // sets the digital pins as output
pinMode(blueLED, OUTPUT);
pinMode(greenLED, OUTPUT);
Serial.begin(9600); // Open serial communication for reporting
}
void loop()
{
i += 1; // Count loop
irVal = analogRead(irIn); // read input pins, convert to 0-255 scale
if (irVal < 300)//if (irVal<341)
{
redVal= 255;
greenVal= 1;
blueVal= 1;
}//end of if
else if (irVal< 600)//else if (irVal< 682)
{
redVal= 1;
greenVal= 1;
blueVal= 255;
}//end of else if
else
{
redVal= 1;
greenVal= 255;
blueVal= 1;
}//end of else
analogWrite(redLED, redVal); // Send the new value to LEDs
analogWrite(blueLED, blueVal);
analogWrite(greenLED, greenVal);
if (i % wait == 0) // If enough time has passed...
{
if ( irVal > sens ) // If old and new values differ
// above sensitivity threshold
{
if (PRINT) // ...and if the PRINT flag is set...
{
Serial.print("The value of IR sensor: "); // ...then print the values.
Serial.print(irVal);
PRINT = 0;
}
}
else
{
PRINT = 1; // Re-set the flag
}
}
}
Posted at 05:46 PM in Code, Maze Hsiao | Permalink | Comments (0) | TrackBack (0)
Here's the fine video of my IR sensor actually working!!
Another IR sensor + 3 LEDS from Joana Kelly on Vimeo.
I had some wacky issues connecting my IR sensor, but found a useful diagram, also including here:
I ended up adapting Matt's code also. My original code made the lights flicker a lot, but Matt averaged out the IR signal quite effectively. Kudos to you, sir. Matt's code is also after the jump.
Posted at 05:18 PM in Code, Hardware Photos, Joana Kelly | Permalink | Comments (2) | TrackBack (0)
3 LED IR Setup from Mouse & the Billionaire on Vimeo.
I had some problems earlier with light flickering, but I solved this by averaging the input from the IR sensor and smoothing out the results. Works great now.
Posted at 01:33 PM in M Bethancourt | Permalink | Comments (0) | TrackBack (0)
Posted at 07:38 PM in Code, Hardware Photos, Jennifer Dopazo | Permalink | Comments (0) | TrackBack (0)
I set three ranges of distance for each led.
IR sensor + RGB led from Hsiang Ju Hung on Vimeo.
Here is the code: Download IR_RGB
.
And I did a test for floating duck.
I made a plastic base installed IR sensor for duck. And put it into a container (6"*6"*6").
Then kept adding water into it.
Here is the height of the water V.S. analogRead
1 inch : -255
2 inch : -65
3 inch : -170
4 inch : -240
Yeah~ it works in water!!! The voltage changes with the height.
But even I tried many times to modify the proper range for each led, I still cannot make leds switch with the value. Um... maybe it is because it is always negative value and it changes non-linearly..... have no idea yet.
UPDATE: I tried to do it without water in the same distance but still failed. It only turned on one led. I found that it might because it is below 10 cm which is out of Sharp sensor range(10-80cm). So I think I need to measure the proper height of water in tub to see if the sensor is suitable for it first. 10/28
Posted at 09:44 PM in Hsiang Ju | Permalink | Comments (0) | TrackBack (0)
I would like to make a bunch of antisocial animal plush toys. They are antisocial and they have antisocial behaviors, but they do cute things.
Ideas of toy function so far:
1. stick out tongue
2. crossed arms
3. yell "shut up" when it detects words it doesn't like
4. puff out cheeks
5. never be face to face with you
6. air guitar
7. it will roll its eyes and say "what ever"
8. when holding the toy, it would say "leave me alone"
They all have the same characteristic: they'll feel embarrassed after doing "bad things".
Posted at 07:20 PM in Maze Hsiao | Permalink | Comments (0) | TrackBack (0)
Winchip Recorder from Fuki on Vimeo.
Posted at 06:10 PM in Taeko Fukamoto | Permalink | Comments (0) | TrackBack (0)
At this time in the semester, I can't stop thinking about my thesis, so I'd like to make something related.
For my thesis, I'm exploring simple games that are fun and effective for neuro-rehabilitation. I've come up with several simple games that I'm hoping to develop further, both conceptually and technically.
Each game focuses on a particular function of disability. For the first one, I'd like to focus on proprioception (one's sense of position in space). A person with a proprioception problems often have difficulty sensing where their arms/legs are in space. For this reason, it's importan to exercise and train the person by making connections between distance, proximity and posiiton. One of the games that I have been playtesting is similar to "Pin the Tail." Using sensors can possibly help the patient in getting closer to the "target".
Another game that I'm looking into is called Blinded Samurai. There are two main players, who have to find each other, as they listen to their personal guides.
Posted at 06:09 PM in Taeko Fukamoto | Permalink | Comments (0) | TrackBack (0)
#1 A penny a day, keeps a piggy happier
As money gets more, the piggy's cheek becomes redder/ piggy sounds more pleased.
While you are taking a bath, the duck will change color with the wave. Or the duck will inform you once the water arrives certain height while you are away and keep storing hot water in the tub to avoid wasting time or water.
#3 Answering Door
Using IR sensor to release voice message from the host. Or using push button to allow visitors to leave their message to the host.
#4 No real height
This height measurement machine won't hurt anyone with telling your real. It will only tell you who else has the same height as you.
Posted at 05:57 PM in Hsiang Ju | Permalink | Comments (0) | TrackBack (0)
Posted at 05:06 PM in Hardware Photos, Jessica Floeh | Permalink | Comments (0) | TrackBack (0)
1) Omnipod Installation -- I have type 1 diabetes, on an insulin pump, etc. Recently I have been looking into this newer pump called the 'Omnipod.' Basically each pod is a microcontroller, a couple gears, batteries, a needle, plastic catheter, and reservoir of insulin. You get 10 of them a month, they are controlled wirelessly by a PDM device that tells the pod how many times to move its gear to get insulin out, basically. So I was thinking of hacking into a couple pods. I was given some free ones by the sales-rep...and have already taken one apart. I'm so geeky. Anyway, I was thinking of trying to re-control it, without the PDM. Perhaps making the gear move/some kind of liquid coming out. I think I could also attach a speaker to it and make it say things like "0.5 units" or whatever. I want to bring it alive! Maybe there could be three or four on a wall, with proximity sensors, lit up by LEDS, and when someone gets close they will drip liquid.
See my other project ideas at the following link
Posted at 04:57 PM in Jessica Floeh | Permalink | Comments (0) | TrackBack (0)
Pandas
This concept involves two pandas, which both detect presence. One panda, when detecting someone near by, sends a message to the second panda, which sneezes, alerting the second person of the first person's presence. Naturally this concept makes the most sense when the two pandas are in different places.
Time Bird
The tenatively named Time Bird monitors the amount of time someone spends in front the computer. The bird will chirp every hour, counting the number of hours that pass, and when someone gets up from the computer the bird will reset.
Ambient Sound Frame
This photo frame would play ambient sound from the day the photograph was taken, or a recorded message related to the photograph when someone picks up the frame or gets close to it.
Proximity Alert
I thought about this the other day while setting up a photo studio in my apartment. I came close to falling over the lights and cords several times and could have used a little extra help steering clear of all the obstacles.
Magic Music Box
The music box would play a short tune, much like a traditional music box (or snow globe), but it would mysteriously sense your presence and begin to play! Like Magic!!
Posted at 04:48 PM in Joana Kelly | Permalink | Comments (0) | TrackBack (0)
Posted at 04:27 PM in Hsiang Ju | Permalink | Comments (0) | TrackBack (0)
I got this robot a few months ago because I thought he was cool. He is named ChatBot, except his chat functionality doesn't work. You are supposed to be able to record on his little tape face and he'll play it back to you. Instead he just goes forward and turns (He can't go backwards. Poor chatbot). This project would help give ChatBot back his voice, and also, as a bonus, it will let him warn you about his proximity to objects that might hurt him (like walls).
Taunting Cat ToyMy cats like cat toys. They are also feisty and tend to think they are (every pun intended) the cat's pajamas. I propose a cat toy that will a) entertain them and b) put them in their place. I like the idea of the cat toy sensing motion, and, if nothing has come close to it recently, it will go through one of its 10 pre-recorded taunts. Only after the cat approaches it will it tone down the insults. I could also include a motion sensor that could do something when it was rolled. Fun!
Facebook AdictsAre you tired of being tied to Facebook? Well how's about a little sensor that pulls data from your facebook account and tells you "There's no need to check your account now," whenever you get close to your computer? Could be useful.
Posted at 01:27 PM in M Bethancourt | Permalink | Comments (0) | TrackBack (0)
Below is a video of my chipcorder working, and some photos of what it would look like if I could get it to work inside it's cute little box-like shell. I've apparently killed my other chip, and I think I've done something iffy to the volume pin on my second chip. Ruh roh. Before I screwed everything up, though, things were beautiful:
Chipcorder with Buttons from Joana Kelly on Vimeo.
The Case
Look, there's my speaker, some holes for the LEDS, and all my buttons! Hooray!
Lodged
Also, this is a photograph of some stuff from Sparkfun lodged in my mailbox. Great! I know it looks like maybe if I tilt the box then it will slide out of the mailbox quite easily, but I assure you it does not work. I'm going to hack apart the box inside the mailbox tomorrow. I'll let you know how it goes.
Posted at 02:06 AM in Hardware Photos, Joana Kelly | Permalink | Comments (0) | TrackBack (0)
Below are some storyboards of concepts I was thinking about. Some of them are kinda 'out there' and probably not completely feasible to do. But I'm throwing them out there anyways...
Concept 1: The Secret Teller
Description: A lamp detects when someone is in its proximity and lures that person toward it by inviting the person to hear a secret. When a person approaches, the the lamp fades low and will blurt out some random quote or embarrassing sounds, etc. It's silly. That's the point.
Concept 2: 3D Theater Box
Description: A small box with 3D lenses lights up inside when a person peers in it, revealing a little story told through a strip of anaglyphs. User listens to story and moves the strip forward when prompted by the narration.
Concept 3: The Gathering Table
Description: A lit table repeatedly asks someone to sit with it. When a person does, the light on that side of the table goes off and the table then repeatedly asks someone else to site with them. Once a second person sits, the light on their side of the table goes off and the table invites the two people to have some conversation.
Concept 4: Red Light/Green Light
Description: A cube asks people who get near it to relocate it elsewhere. Using an accelerometer to detect how it's moving, the cube get scared as it's being moved and will freak out if it's moved too fast. This will probably make the user want to put the cube down. And once the cube is set back down, it will only ask to be moved again...
Concept 5: Thesis Prototype
Description: A dual trash/recycling bin make 'healthy' and 'unhealthy' sounds depending which bin wast is thrown into. If more trash than recyclables are thrown away, the bin glows a yucky red/warning color. If more recyclables than trash are thrown away, the bin glows a happy green color.
Posted at 02:05 AM in Katrina Bekessy | Permalink | Comments (0) | TrackBack (0)
Posted at 01:58 AM in Jennifer Dopazo | Permalink | Comments (0) | TrackBack (0)
Posted at 01:56 AM in Jennifer Dopazo | Permalink | Comments (0) | TrackBack (0)
Yes, the Winbond circuit now comes in a sleeker, more stylish look complete with toggle power switch, built-in 1/8" jack for recording, and mystery buttons for playback which I haven't labeled yet. Ships with random quotes from Don Hertzfeldt animations. Bonus.
The New Boom(less) Box. from Katrina Bekessy on Vimeo.
Here are some pics for some details...
Title: The Boom Box
Description: Box with matte board top custom cut to accommodate playback buttons, the speaker, LED's, toggle power switch, and jack for recording from device.
Title: Top View
Description: Toggle switch has been turned on, as shown by the lit LED.
Title: Closeup
Description: A closer look at the switch, the jack, and the LED's. One LED signifies power, and the other blinks when performing a playback action.
Title: Another Closeup
Description: This closeup includes the playback buttons. They're not labeled yet, but they will be. I promise.
Title: Boom Box Guts
Description: Top is attached with Velcro for easy removal. Inside, one breadboard contains the circuit with chip and the other is for button placement. A paper cup help to reverberate the sound from the speaker and a battery pack is hooked up to a 5 Volt regulator which is then controlled by the toggle switch. Huge thanks goes out to jumper cables and electrical tape.
Title: Another Angle
Description: In case you wanted to actually follow my wiring, here it is!
Title: The Meat of It
Description: How can I even begin to explain this thing? Thank goodness for datasheets.
Posted at 01:17 AM in Hardware Photos, Katrina Bekessy | Permalink | Comments (0) | TrackBack (0)
Yup, it works. But the sound is pretty bad. I had to turn up the sound on my computer to the max to get the chip to record from it at an audible volume. I guess my next step would be to figure out how to actually control the volume from the chip. I recorded 2 tracks: "A Little Night Music" by Mozart and "Young Folks" by Peter Bjorn & John. Watch the video:
Katrina's Winbond Chip: Attempt #1 from Katrina Bekessy on Vimeo.
Here are a couple of photos:
Photo: The whole circuit.
Description: Here it is. I decided that I really don't like wire wrap - it always breaks! So I used 20AWG wire for the 1/8" audio plug, which is sticking out next to the yellow LED at top. I also added a 5-Volt regulator to power the board directly from the battery but immediately realized that there wasn't enough room for it. So it's just being powered from an Arduino board right now.
Photo: Top View
Description: Not much to say about this one...Just wanted you to be able to see the entire board clearly.
Posted at 02:00 PM in Hardware Photos, Katrina Bekessy | Permalink | Comments (0) | TrackBack (0)
Posted at 11:51 PM in Jennifer Dopazo | Permalink | Comments (0) | TrackBack (0)
Posted at 11:49 PM in Jennifer Dopazo | Permalink | Comments (0) | TrackBack (0)
Learning to code an Arduino can be pretty confusing as most calculations will occur 'behind the scenes' of a sketch. Bitlash could help provide some quick answers for testing/learning -
Posted at 02:46 PM in Jennifer Dopazo | Permalink | Comments (0) | TrackBack (0)
This was pretty interesting for me, and maybe some of you would like to build one!
Enjoy.
Instructable link
Posted at 02:33 PM in Jennifer Dopazo | Permalink | Comments (0) | TrackBack (0)
Posted at 06:02 PM in Maze Hsiao | Permalink | Comments (0) | TrackBack (0)
Multicolor LED + IR sensor from Jessica Floeh on Vimeo.
Click below for the code:
Posted at 06:05 PM in Code, Jessica Floeh | Permalink | Comments (0) | TrackBack (0)
Last week's assignment was "re-packaged" into the soap box. Few steps were necessary for this to work.
The LED was cut and a wire was attached to each leg:
Holes were drilled into the lid, and the sensor was glued:
Color Mixer in Soap Box from Fuki on Vimeo.
Posted at 05:16 PM in Code, Hardware Photos, Taeko Fukamoto | Permalink | Comments (0) | TrackBack (0)
What a disaster! I've ruined one an IR sensor, and only just about managed to get this second one in action. I haven't changed my code (yet), so I'm still using the code from the Arduino site. The code can been seen below.
Color Mixer with an IR Sensor and a tri-color LED from Joana Kelly on Vimeo.
Here are some fine photos of the thing in action.
The Color Mixer
This is what my color mixer looks like from the top. The black rectangle on the right is my IR sensor. I'd like to make a nicer case for this soon.
The Innards
Here are the innards of my color mixer. It's kind of a mess.
The Disaster
Through the simultaneous use of solder, wrapping wire, and hot glue, I finally got this working, for the most part. I do not recommend this approach. Jumper wires are definitely the way to go.
Posted at 04:59 PM in Code, Hardware Photos, Joana Kelly | Permalink | Comments (0) | TrackBack (0)
What up yo!
Check out my lil IR sensor with a full-color LED (aka RGB). It didn't have to change my code, only replace my potentiometer with my IR sensor and my 3 LEDs with the 1 full-color LED.
Sweetness.
IR sensor light from Lynn WasHere on Vimeo.
p.s. here's the code:
/*
* Code for making one potentiometer control 3 LEDs, red, grn and blu, or one tri-color LED
* The program cross-fades from red to grn, grn to blu, and blu to red
* Debugging code assumes Arduino 0004, as it uses Serial.begin()-style functions
* Clay Shirky <[email protected]>
*/
// INPUT: Potentiometer should be connected to 5V and GND
int potPin = 0; // Potentiometer output connected to analog pin 3
int potVal = 0; // Variable to store the input from the potentiometer
// OUTPUT: Use digital pins 9-11, the Pulse-width Modulation (PWM) pins
// LED's cathodes should be connected to digital GND
int redPin = 9; // Red LED, connected to digital pin 9
int grnPin = 10; // Green LED, connected to digital pin 10
int bluPin = 11; // Blue LED, connected to digital pin 11
// Program variables
int redVal = 0; // Variables to store the values to send to the pins
int grnVal = 0;
int bluVal = 0;
int DEBUG = 1; // Set to 1 to turn on debugging output
void setup()
{
pinMode(redPin, OUTPUT); // sets the pins as output
pinMode(grnPin, OUTPUT);
pinMode(bluPin, OUTPUT);
if (DEBUG) { // If we want to see the pin values for debugging...
Serial.begin(9600); // ...set up the serial ouput in 0004 format
}
}
// Main program
void loop()
{
potVal = analogRead(potPin); // read the potentiometer value at the input pin
if (potVal < 341) // Lowest third of the potentiometer's range (0-340)
{
potVal = (potVal * 3) / 4; // Normalize to 0-255
redVal = 256 - potVal; // Red from full to off
grnVal = potVal; // Green from off to full
bluVal = 1; // Blue off
}
else if (potVal < 682) // Middle third of potentiometer's range (341-681)
{
potVal = ( (potVal-341) * 3) / 4; // Normalize to 0-255
redVal = 1; // Red off
grnVal = 256 - potVal; // Green from full to off
bluVal = potVal; // Blue from off to full
}
else // Upper third of potentiometer"s range (682-1023)
{
potVal = ( (potVal-683) * 3) / 4; // Normalize to 0-255
redVal = potVal; // Red from off to full
grnVal = 1; // Green off
bluVal = 256 - potVal; // Blue from full to off
}
analogWrite(redPin, redVal); // Write values to LED pins
analogWrite(grnPin, grnVal);
analogWrite(bluPin, bluVal);
if (DEBUG) { // If we want to read the output
DEBUG += 1; // Increment the DEBUG counter
if (DEBUG > 100) // Print every hundred loops
{
DEBUG = 1; // Reset the counter
// Serial output using 0004-style functions
Serial.print("R:"); // Indicate that output is red value
Serial.print(redVal); // Print red value
Serial.print("\t"); // Print a tab
Serial.print("G:"); // Repeat for grn and blu...
Serial.print(grnVal);
Serial.print("\t");
Serial.print("B:");
Serial.println(bluVal); // println, to end with a carriage return
}
}
}
Posted at 03:13 PM in Lynn Maharas | Permalink | Comments (0) | TrackBack (0)
So here it is! And it works pretty well. With my setup, the long pin on the LED actually goes to power and the other three hook up to the PMW pins on the Arduino and then go to ground (I stuck some resistors in there before taking that pins to ground). Here's what it looks like:
IR Proximity Color Mixer w/ Tri-Color LED from Katrina Bekessy on Vimeo
And here's some pics of the box itself and its innards:
The Box
Just a little cardboard gift box I cut up to make little windows with vellum paper...I used Velcro to keep the top closed.
The Insides!
Bascially the breadboard is stacked on top of the battery pack which is on top of the Arduino. Not elegant at all...
Close up of LED
Just a closer peek at the LED setup with the resistors
I found this webpage with a great example of a tri-color LED used with the exact IR sensor we're using. It gave code for averaging/normalizing the sensor readings so that it won't flicker at all. I tried to use it, but I couldn't get it to work correctly. If anyone else wants to take a stab at it, check it out: http://letsmakerobots.com/node/672
Here's a plain text file of my Arduino code. In a different file, I used the serial commands to read the range of my sensor...The highest it went was about 620, but I wasn't really sure what that meant or how to make that meaningful through the way it would change the colors of the LED.
Posted at 02:31 PM in Hardware Photos, Katrina Bekessy | Permalink | Comments (0) | TrackBack (0)
Here's a short video of a color mixer I made using a tri-color led. I used the color mixer code from the Arduino site. To see the code, click the link at the bottom of the post.
Color Mixer from Joana Kelly on Vimeo
Color Mixer Insides
This is the inside of the mixer. That's the arduino on the left! Note I finally got that tri-color led working. Yesss! Turns out the short pin does go to power....good to know.
Continue reading "Color Mixer with a Potentiometer and a Tri-Color LED" »
Posted at 07:04 PM in Code, Hardware Photos, Joana Kelly | Permalink | Comments (0) | TrackBack (0)
Posted at 04:32 PM in Jennifer Dopazo | Permalink | Comments (0) | TrackBack (0)
Ever since I was a child, I was fascinated with things that were small. There's something imaginative and fairytale-like when everyday-objects are transformed into miniatures. Even with electrical objects like laptops, mp3 players and automobiles, the inner-child in me--and maybe in most of us?-- becomes excited with things that are reduced in size.
Posted at 04:23 PM in Taeko Fukamoto | Permalink | Comments (0) | TrackBack (0)
my color mixer from maze on Vimeo.
Materials: Arduino, jumper wires, potentiometer, 9v battery, LEDs, resistors, DC power plug, tracing paper, scotch tape, fiberfill
Here is my code:
/*
*Color Mixer
*Tzumei M. Hsiao
*I modified the code from "Coffee-cup" color mixer on Arduino.cc
*/
// Analog pin settings
int potIn = 3; // the potentiometer connected to the analog pin 3
// Digital pin settings
int redLED = 9; // LEDs connected to digital pins 9, 10 and 11
int blueLED = 10; // (Connect cathodes to digital ground)
int greenLED = 11;
// Values
int potVal = 0; // the variable to store the input from the potentiometer
int redVal = 0; // the variable to store the value of red LED
int greenVal = 0; // the variable to store the value of green LED
int blueVal = 0; // the variable to store the value of blue LED
// Variables for comparing values between loops
int i = 0; // Loop counter
int wait = (1000); // Delay between most recent pot adjustment and output
int sens = 3; // Sensitivity threshold, to prevent small changes in
// pot values from triggering false reporting
// FLAGS
int PRINT = 1; // Set to 1 to output values
void setup()
{
pinMode(redLED, OUTPUT); // sets the digital pins as output
pinMode(blueLED, OUTPUT);
pinMode(greenLED, OUTPUT);
Serial.begin(9600); // Open serial communication for reporting
}
void loop()
{
i += 1; // Count loop
potVal = analogRead(potIn); // read input pins, convert to 0-255 scale
if (potVal< 341)
{
potVal= (potVal* 3) / 4; //normalize to 0-255
redVal= 255-potVal;
greenVal= potVal;
blueVal= 1; //blue off
} //end of if
else if (potVal< 682)
{
potVal= ((potVal-341)*3) / 4; //normalize to 0-255
redVal= 1; //red off
greenVal= 255-potVal;
blueVal= potVal;
} //end of else if
else
{
potVal= ((potVal-682)*3)/ 4; //normalize to 0-255
redVal= potVal;
greenVal= 1; //green off
blueVal= 255-potVal;
} //end of else
analogWrite(redLED, redVal); // Send the new value to LEDs
analogWrite(blueLED, blueVal);
analogWrite(greenLED, greenVal);
if (i % wait == 0) // If enough time has passed...
{
if ( potVal > sens ) // If old and new values differ
// above sensitivity threshold
{
if (PRINT) // ...and if the PRINT flag is set...
{
Serial.print("The value of potentiometer: "); // ...then print the values.
Serial.print(potVal);
PRINT = 0;
}
}
else
{
PRINT = 1; // Re-set the flag
}
}
}
Posted at 01:18 AM in Code, Maze Hsiao | Permalink | Comments (0) | TrackBack (0)
Recent Comments