I need some code assistance, please. I cannot figure out how to get pin 13 or 11 tap at a fast speed and the other pin tap much slower. This needs to be in a continuous loop, no delays. Is it possible? Here is what I have now, but I am tired of carrying 2 Arduinos. Can't one Arduino do what I want? Please assist me. I searched Google as much as I could. I gave up! Thank you. I really appreciate it.
It appears that you are attempting to generate a 63mS pulse (approx 50% duty cycle) on pin 13, and the same on pin 11 (but with inverted phase) in a repeating cycle (about 8 Hz).
You talk about 2 Arduinos. How are these interconnected together with your application and for what purpose ?
Hi guys! Thank you for replying. Yes I am tapping my iphone screen, playing tapping games. I carry 2 Arduinos with the same code above programmed to both. However, one Arduino/code is slightly modified to allow for the 16ms speed. I use a lithium ion battery pack with 2 USB plugs to power the Arduinos. I only plug 1 tapper in to pin 13 on one Arduino and the other Arduino 1 tapper is plugged in to pin 11.
I basically need pin 13 to run at a continuous 63ms and pin 11 to run at a continuous 16ms with no delays on only 1 Arduino.
Hope that was a clearer explanation and makes sense.
UKHeliBob, I really appreciate your attempt to help me out. But, you’re speaking greek to me. I should have mentioned that I did not write the original code above and have never personally wrote any code for Arduino or anything. Unfortunately, I cannot get a hold of the person who wrote the code above. I been attempting to research the code and possibly just rewrite it, too bad I just can’t figure it out.
I want the pins to tap at a speed I can adjust accordingly, start out with pin 13 at 62ms and pin 11 at 16ms. I just need the pins to tap continuously, no delay between taps like a tap tap tap tap...etc.
Oh yeah, to answer your question, no end to the tapping. Tap continuously.
You can also do it like this as described in post #4. You still have to answer the question about the spaces between the pulses. I've assumed a 50% duty cycle below.
#include <TimerOne.h> // you may have to install this
int touch1 = 13;
int touch2 = 11;
unsigned long touch1_MARK_ms = 63 ; // tune these parameters to suit your application
unsigned long touch1_SPACE_ms = 63 ;
unsigned long touch2_MARK_ms = 16 ;
unsigned long touch2_SPACE_ms = 16 ;
void Timer_ISR() {
// called every 1ms
static unsigned int touch1_counter = 0 ;
static unsigned int touch2_counter = 0 ;
// touch1
if( touch1_counter == 0 ) digitalWrite(touch1, HIGH );
else if ( touch1_counter == touch1_MARK_ms ) digitalWrite(touch1, LOW );
touch1_counter ++ ;
if ( touch1_counter == touch1_MARK_ms + touch1_SPACE_ms ) touch1_counter = 0 ;
// touch2
if( touch2_counter == 0 ) digitalWrite(touch2, HIGH );
else if ( touch2_counter == touch2_MARK_ms ) digitalWrite(touch2, LOW );
touch2_counter ++ ;
if ( touch2_counter == touch2_MARK_ms + touch2_SPACE_ms ) touch2_counter = 0 ;
}
void setup() {
pinMode(touch1, OUTPUT);
pinMode(touch2, OUTPUT);
Timer1.initialize(1000); // initialize timer1 1000 uS period
Timer1.attachInterrupt(Timer_ISR); // attaches Timer_ISR() as a timer overflow interrupt
}
void loop() { }
Hi guys, I am not sure how long each tap lasts. I think it just follows the default blink code loaded to the Arduino board. The current tap speed between taps is perfect. Yes, the LED on the Arduino blinks in sequence with my tappers.
The basic Blink sketch that the Arduino comes loaded with and which is included in the examples with the IDE turns on the LED for one second then turns it off for one second. To help you we need to know how long each output should remain turned on each time it happens.
If you are happy with equal on and off periods for each tapper, albeit at different frequencies, that is easier to program.
Thank you for both code examples! I really appreciate it guys!!
UKHeliBob,
Would I paste your code you provided as a new code? Or do I paste it somewhere in my original code in my first post? Sorry, I apologize. I am incredibly dumb when it comes to this coding stuff to be honest.
Would I paste your code you provided as a new code?
The code that I posted is a complete program. Do a File/New in the IDE. Delete all of the text in the default template that should appear and paste in the whole of my program. Compile and upload it and report back what happens and how/if it does what you want.
Not to discredit 6V6GT!! I really appreciate both of you.
At first UKHeliBob, pin 11 wasn’t tapping at all. I was going to write back and tell you, then I noticed your response about a bug you found. I added that line and now it works PERFECTLY!!!