0

NeoPixelRing code
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: NeoPixelRing code

by mqdean on Fri Feb 02, 2018 11:30 am

Thanks a lot. Seriously, you guys are superb.

mqdean
 
Posts: 27
Joined: Mon Jan 29, 2018 11:54 pm

Re: NeoPixelRing code

by mqdean on Fri Feb 02, 2018 11:33 am

Thanks a lot. You guys are great.

Will use the code tag next time..newbie :)

mqdean
 
Posts: 27
Joined: Mon Jan 29, 2018 11:54 pm

Re: NeoPixelRing code

by adafruit_support_bill on Fri Feb 02, 2018 11:51 am

Good to hear it is working for you. Thanks for the follow-up.

adafruit_support_bill
 
Posts: 69769
Joined: Sat Feb 07, 2009 10:11 am

Re: NeoPixelRing code

by mqdean on Fri Feb 02, 2018 11:17 pm

Hi again.
Is it possible to configure in a way that the pixel lights up only when the serial value falls below 20 suddenly and returns to original values immediately. For instance, I want the pixel to light up only when the fsr is being hit by a fast moving object and not knocks by our body.

mqdean
 
Posts: 27
Joined: Mon Jan 29, 2018 11:54 pm

Re: NeoPixelRing code

by adafruit_support_bill on Sat Feb 03, 2018 8:13 am

That is possible, but requires some more advanced programming techniques.

You will need some global 'state' variables to keep track of when the FSR is pressed and released. And you will have to eliminate the delay() from the code and use the millis() function for timing.

https://www.arduino.cc/reference/en/lan ... me/millis/

adafruit_support_bill
 
Posts: 69769
Joined: Sat Feb 07, 2009 10:11 am

Re: NeoPixelRing code

by mqdean on Sat Feb 03, 2018 9:55 am

Thank you. Are there any examples I can have a look at.

mqdean
 
Posts: 27
Joined: Mon Jan 29, 2018 11:54 pm

Re: NeoPixelRing code

by adafruit_support_bill on Sat Feb 03, 2018 10:56 am


adafruit_support_bill
 
Posts: 69769
Joined: Sat Feb 07, 2009 10:11 am

Re: NeoPixelRing code

by mqdean on Sat Feb 03, 2018 11:22 am

I am trying to do something similar to the link below. I want the force from the foam darts to trigger the pixel and not my fingers. To visualize, the graph in the serial plotter will have a sharp bend at the bottom when the foam dart hits the fsr.

For example, the serial value should be below 20 for less then 1/100th of a second for the pixel to light up.

Sorry, I am new to this and have been cracking my head the whole day on this.

https://makezine.com/2017/02/20/nerf-dart-clock/

Thank you for the prompt reply.

mqdean
 
Posts: 27
Joined: Mon Jan 29, 2018 11:54 pm

Re: NeoPixelRing code

by adafruit_support_bill on Sat Feb 03, 2018 12:16 pm

So you would want to record the time (via millis()) when the value goes below 20, then record the time when the value returns to normal. If the difference between the two is less than 100, you can count it as a hit.

adafruit_support_bill
 
Posts: 69769
Joined: Sat Feb 07, 2009 10:11 am

Re: NeoPixelRing code

by mqdean on Sat Feb 03, 2018 6:39 pm

Yes. So the starting point of the value will be when the value goes below 20 and the value should go up above 20 before 100millis.

mqdean
 
Posts: 27
Joined: Mon Jan 29, 2018 11:54 pm

Re: NeoPixelRing code

by adafruit_support_bill on Sat Feb 03, 2018 7:28 pm

Just record the time when it goes below 20. Then record the time when it returns to normal. If it is more than 100ms, then ignore it and start all over again.

adafruit_support_bill
 
Posts: 69769
Joined: Sat Feb 07, 2009 10:11 am

Re: NeoPixelRing code

by mqdean on Sun Feb 04, 2018 11:21 am

The below code works fine. When I press the fsr at a certain pressure for five seconds, one pixel lights up.

Code: Select all | TOGGLE FULL SIZE
#include <EasyNeoPixels.h>

#include <EasyNeoPixels.h>

#include <Adafruit_NeoPixel.h>

#define PIN 6

// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(16, PIN, NEO_GRB + NEO_KHZ800);

int force;
int interval = 5000;     // the time we need to wait
int previousMillis = 0;  // millis() returns an unsigned long.
int currentMillis;

void setup() {
  pinMode(9, INPUT_PULLUP);
  strip.setBrightness(10);
  strip.begin();
  strip.show();
}

int pixelCount = 0;

void loop() {
   force = analogRead(9);
   Serial.println(force);
   currentMillis = millis();
if ((force < 50) && ((currentMillis - previousMillis) > interval))
{
      strip.setPixelColor(pixelCount++, 0, 255, 0);
      strip.show();
      previousMillis = millis();
   }
}
Last edited by mqdean on Sun Feb 04, 2018 11:29 am, edited 3 times in total.

mqdean
 
Posts: 27
Joined: Mon Jan 29, 2018 11:54 pm

Re: NeoPixelRing code

by mqdean on Sun Feb 04, 2018 11:26 am

But when I want the pixel to light up when the fsr is pressed at a certain pressure and interval is less than 1000ms, it does not work. Below is the code.

Code: Select all | TOGGLE FULL SIZE
#include <EasyNeoPixels.h>

#include <EasyNeoPixels.h>

#include <Adafruit_NeoPixel.h>

#define PIN 6

// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(16, PIN, NEO_GRB + NEO_KHZ800);

int force;
int interval = 1000;     // the time we need to wait
int previousMillis = 0;  // millis() returns an unsigned long.
int currentMillis;

void setup() {
  pinMode(9, INPUT_PULLUP);
  strip.setBrightness(10);
  strip.begin();
  strip.show();
}

int pixelCount = 0;

void loop() {
   force = analogRead(9);
   Serial.println(force);
   currentMillis = millis();
if ((force < 50) && ((currentMillis - previousMillis) < interval))
{
      strip.setPixelColor(pixelCount++, 0, 255, 0);
      strip.show();
      previousMillis = millis();
   }
}

mqdean
 
Posts: 27
Joined: Mon Jan 29, 2018 11:54 pm

Re: NeoPixelRing code

by mqdean on Sun Feb 04, 2018 11:30 am

Kindly assist me on the coding for the above.

Thank you!

mqdean
 
Posts: 27
Joined: Mon Jan 29, 2018 11:54 pm

Re: NeoPixelRing code

by adafruit_support_bill on Sun Feb 04, 2018 12:10 pm

Something like ...
Code: Select all | TOGGLE FULL SIZE
int force;
int pixelCount = 0;
long impactTime = 0;

void loop()
{
    force = analogRead(9);
    Serial.println(force);
    currentMillis = millis();
   
    if (force < 50)
    {
        // record the time when it goes below 50.
        impactTime = currentMillis();
        while(analogRead(9) < 50) { } // do nothing.
    }
    if (force > 60) // check for return to 'normal'
    {
        if ((currentMillis() - impactTime) < 100)  // If less than 100 ms, record as a hit.
        {
            strip.setPixelColor(pixelCount++, 0, 255, 0);
            strip.show();
        }
    }
}

adafruit_support_bill
 
Posts: 69769
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.


cron