force sensors with 12mm rgb pixels

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
RJ2120
 
Posts: 13
Joined: Sat Feb 16, 2013 2:16 pm

force sensors with 12mm rgb pixels

Post by RJ2120 »

HI

Im working on a project wear i need the force sensor to change the color of the rgb pixels. So that every time you squeeze the sensor it changes the color of the pixels or have it so as your squeezing the sensor the colors are changing until you release at which point it stops on that color. This is possible right?? and Can someone help me figure this out??

RJ2120
 
Posts: 13
Joined: Sat Feb 16, 2013 2:16 pm

Re: force sensors with 12mm rgb pixels

Post by RJ2120 »

No one has any suggestions!!??

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: force sensors with 12mm rgb pixels

Post by adafruit_support_bill »

Yes this is very possible to do. You will need an Arduino, a digital led strand and a 5v power supply as well as an FSR and a 10K resistor.

I'd start be getting the led strand connected and run the example code to make sure it works.
Then I'd hook up the FSR and verify that that works.
From there, it should be fairly easy to combine the two functions so that the FSR can control the strand.

RJ2120
 
Posts: 13
Joined: Sat Feb 16, 2013 2:16 pm

Re: force sensors with 12mm rgb pixels

Post by RJ2120 »

I have downloaded the test code already and have tested both the fsr and rgb leds and they are working properly and i am now working on combining them but that's wear im running into issues. Im kind of new at this and i am having a hard time getting the sketch right

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: force sensors with 12mm rgb pixels

Post by adafruit_support_bill »

Well post what code you have and describe what is not working for you.

RJ2120
 
Posts: 13
Joined: Sat Feb 16, 2013 2:16 pm

Re: force sensors with 12mm rgb pixels

Post by RJ2120 »

Like i said i am new at this and I got kind of a crash coarse in doing sketches i only know the very basics. a friend is supposed to be helping me but hasnt been around and im running out of time as this is for my design class and possible a lighting show. If you could help get me started i believe i can figure the rest out. I dont really have one written up right now have just been trying to combine the two but I wasn't successful so i havent been saving them. I have been using the sketch with an led from here http://learn.adafruit.com/force-sensiti ... ing-an-fsr and the strand test sketch for the 12mm rgb pixels here http://learn.adafruit.com/12mm-led-pixels/code .

RJ2120
 
Posts: 13
Joined: Sat Feb 16, 2013 2:16 pm

HELP!! force sensors with 12mm rgb pixels

Post by RJ2120 »

Can someone please help me!!!!

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: force sensors with 12mm rgb pixels

Post by adafruit_support_bill »

You haven't given us much to work with here. You don't have a clear description of what you want the code to do. And you haven't shown us any attempt to solve this on your own.

RJ2120
 
Posts: 13
Joined: Sat Feb 16, 2013 2:16 pm

Re: force sensors with 12mm rgb pixels

Post by RJ2120 »

Sorry like i said I only know bare basics of writing code i dont even know wear to begin trying to write this. my partner was supposed write the code for me but I cant get a hold of him or i would post what he has so far. I want it so that very time the force sensor is triggered it changes the color of the 12mm pixels which i didnt think would by to difficult. My parents are taking a shot at it tonight if they come up with anything ill post it

tldr
 
Posts: 466
Joined: Thu Aug 30, 2012 1:34 am

Re: force sensors with 12mm rgb pixels

Post by tldr »

first you need to figure out what's the usable range of readings that you'll get from the sensor. doesn't look from the tutorial like it's going to be linear, so you may have to invent some function to map the readings to colors. i'd try to map them to values from 0-255 and feed them to the wheel function from the led strip and pixel example code. that way the hard part's done for you.

that's all i've got. i've never had an fsr to play with.

User avatar
modeller
 
Posts: 118
Joined: Sat Jan 19, 2013 11:12 am

Re: force sensors with 12mm rgb pixels

Post by modeller »

RJ2120 wrote:Sorry like i said I only know bare basics of writing code i dont even know wear to begin trying to write this.
Try writing it out in pseudo code, meaning not real C code but a sort of pllain English like this -

Initialize a force sensor
If the force equals x then show Cyan
If the force equals y then show orange
If the force equals the initial state then show nothing
...

RJ2120
 
Posts: 13
Joined: Sat Feb 16, 2013 2:16 pm

Re: force sensors with 12mm rgb pixels

Post by RJ2120 »

Thanks for the reply. Yeah i understand that much but it seams like theirs a lot more than that to the rgb pixels

RJ2120
 
Posts: 13
Joined: Sat Feb 16, 2013 2:16 pm

Re: force sensors with 12mm rgb pixels

Post by RJ2120 »

ok so here is what i was able to come up with so far. Right now its red when it turns on then when you squeeze lightly it changes to green and when you squeeze hard it turns blue. But as soon as you release it goes back to red so how do i get it so that it stays on the color until you squeeze it again?

Code: Select all

// Choose which 2 pins you will use for output.
// Can be any valid output pins.
// The colors of the wires may be totally different so
// BE SURE TO CHECK YOUR PIXELS TO SEE WHICH WIRES TO USE!
int dataPin  = 2;    // Yellow wire on Adafruit Pixels
int clockPin = 3;    // Green wire on Adafruit Pixels

// Don't forget to connect the ground wire to Arduino ground,
// and the +5V wire to a +5V supply

// Set the first variable to the NUMBER of pixels. 25 = 25 pixels in a row
Adafruit_WS2801 strip = Adafruit_WS2801(25, dataPin, clockPin);

// Optional: leave off pin numbers to use hardware SPI
// (pinout is then specific to each board and can't be changed)
//Adafruit_WS2801 strip = Adafruit_WS2801(25);

// For 36mm LED pixels: these pixels internally represent color in a
// different format.  Either of the above constructors can accept an
// optional extra parameter: WS2801_RGB is 'conventional' RGB order
// WS2801_GRB is the GRB order required by the 36mm pixels.  Other
// than this parameter, your code does not need to do anything different;
// the library will handle the format change.  Examples:
//Adafruit_WS2801 strip = Adafruit_WS2801(25, dataPin, clockPin, WS2801_GRB);
//Adafruit_WS2801 strip = Adafruit_WS2801(25, WS2801_GRB);

/*************************************************************************

FSR testing sketch.  
Connect one end of FSR to 5V, the other end to Analog 0.
Then connect one end of a 10K resistor from Analog 0 to ground
Connect LED from pin 11 through a resistor to ground  
For more information see www.ladyada.net/learn/sensors/fsr.html 

//if (fsrReading < 10) {
//    Serial.println(" - No pressure");
//  } else if (fsrReading < 200) {
//    Serial.println(" - Light touch");
//  } else if (fsrReading < 500) {    
//    Serial.println(" - Light squeeze");
//  } else if (fsrReading < 800) {
//    Serial.println(" - Medium squeeze");
//  } else {
//   Serial.println(" - Big squeeze");

**************************************************************************/ 
 
int fsrAnalogPin = 0; // FSR is connected to analog 0
int fsrReading;      // the analog reading from the FSR resistor divider


void setup() {
    
  strip.begin();

  // Update LED contents, to start they are all 'off'
  strip.show();
}


void loop() {
  //if measured pressure above a certain threshold, trigger string of LEDs
  
  fsrReading = analogRead(fsrAnalogPin);  
// the larger the fsr Reading number the more pressure that was applied.

  if (fsrReading < 200){

    colorWipe(Color(255, 0, 0), 10000);
    delay(125);
  }
   else {
        if (fsrReading < 700){

         colorWipe(Color(0, 255, 0), 10000);
         delay(125);
  }
         else {
            if (fsrReading >= 700){

            colorWipe(Color(0, 0, 255), 10000);
            delay(125);
  }
   }
   }
}

// fill the dots one after the other with said color 
// good for testing purposes 
void colorWipe(uint32_t c, uint8_t wait) { 
   int i;   
   for (i=0; i < strip.numPixels(); i++) { 
         strip.setPixelColor(i, c); 
         
   } 
   strip.show(); 
   delay(wait); 
 } 


void rainbow(uint8_t wait) {
  int i, j;
   
  for (j=0; j < 256; j++) {     // 3 cycles of all 256 colors in the wheel
    for (i=0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel( (i + j) % 255));
    }  
    strip.show();   // write all the pixels out
    delay(wait);
  }
}


/* Helper functions */

// Create a 24 bit color value from R,G,B
uint32_t Color(byte r, byte g, byte b)
{
  uint32_t c;
  c = r;
  c <<= 8;
  c |= g;
  c <<= 8;
  c |= b;
  return c;
}

//Input a value 0 to 255 to get a color value.
//The colours are a transition r - g -b - back to r
uint32_t Wheel(byte WheelPos)
{
  if (WheelPos < 85) {
   return Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if (WheelPos < 170) {
   WheelPos -= 85;
   return Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170; 
   return Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

tldr
 
Posts: 466
Joined: Thu Aug 30, 2012 1:34 am

Re: force sensors with 12mm rgb pixels

Post by tldr »

what's the reading when there's no pressure on the sensor? if you get that reading don't change the color. you may have to figure out how long it takes to change and add a little wiggle room to your code.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”