Go Down

Topic: what input pin is it using? (Read 5 times) previous topic - next topic


yes there is where it is blinking the led i dont actually need that led how can i get rid of that function as ive noticed if i remove void rpm_fun() i get a error

You could remove the blinking by taking out the two lines of code that write HIGH and LOW to the ledPin, and the delay between them.
I only provide help via the forum - please do not contact me for private consultancy.


ok so basically leave it there but take the internals out of it.

would this work or am i barking up the wrong tree?

Code: [Select]

volatile int rpmcount;
int sensorState = 0;
unsigned int rpm;
unsigned long timeold;
int rpm1 =1;

void setup() {
pinMode(INPUT, rpm1);
void loop(){
   if(rpm1>=5) {
      rpm=(60000*rpmcount)/(8*(millis()-timeold)); //the 8 changes to 4 if 4 magnets are used.
      timeold = millis();
      rpmcount = 0;


"i will eventually need 3 hall inputs so how will i overcome that?"

You can have an interrupt on any pin, they are called PCINT.
See NickGammon's writeup on them here
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.


You can keep the blinking led.
Move the blink part outside of the ISR. Set up a global byte variable and make it volatile to use as a blink flag, maybe call it bFlag. When the ISR runs, set that to 1 in the ISR. Then in loop() set up an if ( bFlag ) { } that makes the led blink and sets bFlag = 0.

So your ISR increments rpm count and flags the blink, it runs in next to nothing flat and is ready to service the next interrupt that fast.

IIRC you can set up any I/O pin to interrupt on Level Change. But look into things, maybe you don't need to use interrupts at all. Most things don't at 16 MHz.

You'd do better to learn how to use timers to run multiple tasks without using blocking code.
This is Nick Gammon's site, he's a master at explanations.

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.


would this work or am i barking up the wrong tree?

Wrong tree entirely. You have completely removed the interrupt handler now.

In your original sketch, this interrupt handler was called when you got a falling edge on pin 2:

Code: [Select]

void rpm_fun()
      digitalWrite(ledPin, HIGH);
      digitalWrite(ledPin, LOW);

These are the lines of code that turn ledPin HIGH, wait 50 milliseconds and then turn it LOW again:

Code: [Select]

      digitalWrite(ledPin, HIGH);
      digitalWrite(ledPin, LOW);

If you take those three lines out it will no longer flash the LED and will no longer have that unwise delay() in the interrupt handler.
I only provide help via the forum - please do not contact me for private consultancy.

Go Up