Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coding problem: using infrared sensor as object counter and rgb ledstrip as 7 segment display #785

Open
skennyboiii opened this issue May 1, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@skennyboiii
Copy link

commented May 1, 2019

i am currently creating a project in which I am using an infrared sensor as an object counter and displaying the number of counts onto a 3-digit 7 segment display (with the use of an rgb ledstrip).

The ledstrip is only displaying the counts from 0-9 (singe digit) and when it reaches double digits it stops counting.

Here is my code:

include <Adafruit_NeoPixel.h>

#define PIN 2
#define LEDSPERSEGMENT 1
int ir_pin = 3;
int counter = 0;
int hitObject = false;

Adafruit_NeoPixel strip = Adafruit_NeoPixel(42, PIN, NEO_GRB + NEO_KHZ800);

unsigned long DigitBytes[] = {
0x0003FFFF, // 0
0x000001F8, // 1
0x001C7E3F, // 2
0x001C0FFF, // 3
0x001F81F8, // 4
0x001F8FC7, // 5
0x001FFFC7, // 6
0x000001FF, // 7
0x001FFFFF, // 8
0x001F81FF // 9
};

void setup() {
strip.begin();
Serial.begin(9600);
pinMode(ir_pin,INPUT);
}

void showDigit(int d, int offset) {
unsigned long digit = DigitBytes[d];

for (int i = offset; i < offset + 21; i++) {
if (digit & 1) {
strip.setPixelColor(i, 0xFF0000);
} else {
strip.setPixelColor(i, 0x000000);
}
digit = digit >> 1;
}
strip.show();
}

void showScore(int score) {
int ones = score % 10;
int tens = score / 10;
int hundreds = score / 100;

showDigit(ones, (LEDSPERSEGMENT * 7));
showDigit(tens, (LEDSPERSEGMENT * 7));
showDigit(hundreds, (LEDSPERSEGMENT * 7));

Serial.print(ones);
Serial.println(tens);
Serial.println(hundreds);

}

void loop() {
int val = digitalRead(ir_pin);

if( (val == 0) && (hitObject == false) ){
counter++;
hitObject = true;

}else if( (val ==1) && (hitObject == true) ) {
hitObject = false;
}

showDigit(counter,0);
showDigit(counter, 21);


Serial.println(counter);

}

@skennyboiii skennyboiii changed the title coding problem: infrared sensor as counter and rgb ledstrip as 7 segment display coding problem: using infrared sensor as object counter and rgb ledstrip as 7 segment display May 1, 2019

@marmilicious

This comment has been minimized.

Copy link

commented May 4, 2019

@skennyboiii
The FastLED Github here should mostly be used for FastLED library related bug reports. The code you have shared is using the Adafruilt Neo pixel library. It would be much better to ask in the Adafruit forums where there are lots of helpful folks that can help you out.

Or if you are using the FastLED library you can ask questions or share your project at the reddit forums: http://fastled.io/r

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.