Pages: 1 [2] 3 4   Go Down
Author Topic: BI-DIRECTIONAL PEOPLE SENSOR AND COUNTER USING ARDUINO BOARD  (Read 7184 times)
0 Members and 1 Guest are viewing this topic.
Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34725
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

how do I call the counting code after the interrupts have occured so as to display the count/counter
(incrementing or decrementing) on the 3 digit seven segment display??
You have a variable that contains the value you last sent to the display. At the start of the loop you compare this variable with the count variable. If they are not the same you update the display.
« Last Edit: December 03, 2012, 05:47:40 pm by Grumpy_Mike » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Could you give me a starter please? am starting my display with 000, increment and decrement accordingly as the sensors makes and breaks
I need to understand this more please.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26627
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's a really bad idea to put serial I/O in interrupt routines.
It's a good idea to post code inside code tags.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 159
Posts: 2927
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm gonna repeat one thing I said previously, and then go away. I see no reason to
mess with interrupts here. It's much easier to use polled I/O instead, and by far,
the best way to learn programming is to learn the easy stuff first. You don't have
100 people a second going past the counter.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What's wrong with using interrupts?can you elaborate pls.

thanks
Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 159
Posts: 2927
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

As mentioned, when learning to program, it's generally easier to start with the
simpler and more straightforward constructs, then once you gain some experience,
go on to the more complex constructs. Then you don't get into the sort of troubles
you're getting yourself into. This is all called the Learning Curve.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34725
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Could you give me a starter please?
What is wrong with reply #15.
Also as AWOL says do not print inside ISRs, it screws things up.

If you want help do not ignore it when it is given. If you don't understand it, ask.
Go back and modify that post with code in.
Select the code and then hit the # icon. Then save it.
That will put code tags around the code and we can copy the code into our own system to better help you.
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8620
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

While I did suggest using interrupts I didn't suggest using 4 of them and all that attach/unattach stuff.

My example was simplicity itself, it does however require that the input signal is clean with no bounce. Here's a rejigged version of what you have

Code:
int last_counter = 0;
volatile int counter = 0;

const int S2_pin = 50; // change to whatever pin it's on

void setup() {
  attachInterrupt(0, S1_RISE, RISING);//hooked to pin2 on mega 2560
  Serial.begin(115200);
}

void loop(){
  if (counter != last_counter) {
    Serial.println(counter);
    counter = last_counter;
  }
}

void S1_RISE(){

  if (digitalRead(S2_pin) == HIGH)
    counter++;
  else
    counter--;  

  if (counter < 0) counter = 0;
}



While I agree with oric_dan(333) that interrupts are not needed here if the input signal is clean I actually think interrupts are easier to use. That said I'll do a polled version as well shortly.

EDIT
@stefanoGizz
What sensors are you using? Do they provide a clean bounce-free signal?

______
Rob
« Last Edit: December 03, 2012, 11:48:54 pm by Graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My infrared sensors do give very clean pulses since they are hooked to a schmitt trigger.
My version of interrupts does work well as it captures all the 4 changes on the 2 pins
of my sensors, having said that I still need help integrating the function to display 0-999
incrementing or decrementing as neccessary. I do take the advice from reply #15.
I am also taking in all the advice so far given and much thanks to all.
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8620
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I really don't see why you need all that interrupt stuff, but if it works so be it.

Quote
I still need help integrating the function to display 0-999 incrementing or decrementing as neccessary
Just to be clear, you currently have working code that prints to the serial monitor?

______
Rob

Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Rob,

That's true, I can print on the serial monitor and that's where I can see the counting up/down.
And I also have the code that counts from 0 to 999 back to 0. All I want to know is how to fix the counting
code to be called upon the interrupts occurring so as to update the counter and hold that count till the next sequence of interrupts.
Am glad you are willing to help.
Thanks.

Steffano.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Mike,

I have been thinking of your reply and I feel it makes sense.
Can you please insert an example on my ISR code attached?
this will be a starter for me, bearing in mind that I have the code that
displays 000---999-000, how to call it is a bit of a challenge to me as a newbie.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34725
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What we need to know is how you have the seven segment displays wired up. That schematic you posted did not show what pins were connected to what.

Then before you update the display you have to have code that will multiplex the display, do you have that? We need to see it.

Is it written correctly, there is a lot of rubbish about with very verbose code. This link shows you how to do it properly.
http://www.thebox.myzen.co.uk/Tutorial/Arrays.html
But you have to extend it to cope with the multiplexing.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Graynomad,

I have tried to go your way and it seems that I need more modification as your example code doesn't give me anything on the serial monitor.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34725
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I have also noted that your ISR sketch was more easier
Odd as I don't have an ISR on that page.
Yes that sort of code was just the sort I warned against. So have a good read of that page and write the refresh code properly.
Logged

Pages: 1 [2] 3 4   Go Up
Jump to: