I want to count pulses without interrupt. i am using arduino nano and don't want to block controller when it counting pulses. i am interfacing Bluetooth with arduino so can't use interrupt. so please help me
here is my code:
[int pin=7,s=0,ch=0; #define check 8
unsigned long time_period=0 ,end_time=0,start_time=0,frequency=0;
int previous_pin=0;
int p=0,a=0;
int temp;
void setup() {
// put your setup code here, to run once:
pinMode(pin,INPUT);
pinMode(check,OUTPUT);
Serial.begin(9600);
DDRB = B11111111;
previous_pin = 0;
}
void loop() {
// put your main code here, to run repeatedly:
//temp=digitalRead(pin);
if(a==0 || a==2){
if (digitalRead(pin)== 1 && previous_pin == 0 ){
previous_pin=digitalRead(pin);
p++;
Serial.print("p");
Serial.println(p);
/Serial.print("Digital pin1 ");
Serial.println(temp);
Serial.print("previous pin1 ");
Serial.println(previous_pin);/
It will be more helpful if you provide more details and what you did on this project, where exactly you are stuck and what specific help you want!
Please read How to use forum so you can get maximum out of here!
kalpeshpatil102:
I want to count pulses without interrupt. i am using arduino nano and don't want to block controller when it counting pulses. i am interfacing Bluetooth with arduino so can't use interrupt.
This does not make sense.
Using an interrupt to count pulses is probably the least intrusive way to do so.
If you don't use an interrupt you must poll the relevant pin at regular intervals. That polling has to be sufficiently regular and frequent so that you can be CERTAIN to poll the pin during the period while the pulse is high and during the period while it is low. The requirements for polling will almost certainly have more impact on the rest of your program than an interrupt that is (for example) triggered on the rising edge of the pulse.
The code in the ISR can be as short as
void myISR() {
pulseCount ++;
}
Also, you have not told us how frequent the pulses are or how long is each HIGH and LOW interval.
aarg:
Also, please put all your parentheses on their own separate lines
I got sick of doing that manually all the time when testing other people's code, so added a line to my "formatter.conf" file to do it automatically when I Auto Format:-
#Move opening brackets onto new line
--style=allman --style=bsd --style=break -A1
thank you for reply. Sorry for late reply . i can't use polling function. because i have connected Bluetooth to pin D2 and D3. i think due to polling controller may be block . can i use timer interrupt ? for counting pulses
i think by using timer interrupt there will be no communication problem between Bluetooth device and counting pulses at same time. so i think use timer1 for counting pulses.
kalpeshpatil102:
i think by using timer interrupt there will be no communication problem between Bluetooth device and counting pulses at same time. so i think use timer1 for counting pulses.
You can do that. Get a hold of the AVR datasheet for the device you're using and begin. On the Uno you can use the T0 or T1 input.
because i have connected Bluetooth to pin D2 and D3
OK, because of your pin selection you have eliminated the use of an external interrupt.
I think you will find it easier, and with more commonly found documentation and tutorials, to pursue a pin change interrupt on some other available pin than to implement a pulse counting routine using the input capture pin or the external clock source pin on Timer1.
OldSteve:
I got sick of doing that manually all the time when testing other people's code, so added a line to my "formatter.conf" file to do it automatically when I Auto Format:-
OldSteve:
I got sick of doing that manually all the time when testing other people's code, so added a line to my "formatter.conf" file to do it automatically when I Auto Format:-
#Move opening brackets onto new line
--style=allman --style=bsd --style=break -A1
I have many versions of IDE. How can I make all versions do that ?
Instead, copy it in the same folder of file "preferences.txt" and modify the copy. This way, you won't lose your custom formatter settings when upgrading the IDE
@MalharD , i am using remote XY library.and i want to count pulses and show on smart phone. for this i am using Bluetooth HC05 .with remote XY application for smart phone.