I notice that you don't include the "digitalWriteFast2" library at the top of your code.
Did you not show all of your sketch, or did you not actually include that library?
Edit: And looking at your code, "FDCS" and "CI" are both defined twice. You need to choose different names for one of each.
Or maybe in the second instances, you really just meant to set the "FDCS" and "CI" pins low:-
I think I worked through some of my errors, and edited my code on the first post. I realized I needed to download the DWF library. Then I had to include the library like you suggested. Have't figured out what I need around the if else statement yet.
My intention is to run loop 1000 times after button press then stop and wait for button press. Button press should make two separate square waves on two different digital pins that will control a 12vDC low side gate. I have no idea what I'm doing haha. Thank you for the help Steve!
OK, I made a few changes, and this now compiles fine, but I'm sure it's not doing what you want it to do.
for instance, the button will only ever be read once, during 'setup()'.
#include "digitalWriteFast.h"
//Powerstroke Diesel Flow Bench Controller
const int FDCS = 13; // Fuel Delivery Control Signal
const int CI = 12; // Cylinder Identification
const int buttonPin = 2; // Start Button
//int FDCS = LOW; // FDCS is normally off
//int CI = LOW; // CI is normally off
//int buttonPin = LOW; // Start button is normally off
int buttonState = LOW;
int count;
void setup()
{
buttonState = digitalReadFast2(buttonPin); // Read Start Button State
pinMode(FDCS, OUTPUT); // Fuel Delivery Control Signal
pinMode(CI, OUTPUT); // Cylinder Identification
pinMode(buttonPin, INPUT); // Start Button
digitalWrite(FDCS, LOW);
digitalWrite(CI, LOW);
}
void loop()
{
if (buttonState == HIGH) // Button is pressed
{
while (count < 1000 ) // Need 1000 counts
digitalWriteFast2(FDCS, HIGH); // Turn FDCS on 12v
delayMicroseconds(1720); // Stay on
digitalWriteFast2(CI, HIGH); // Turn CI on 12v
delayMicroseconds(6880); // Stay on
}
else
{
digitalWriteFast2(FDCS, LOW); // FDCS is off
delayMicroseconds(1720); // 50% Duty Cycle
digitalWriteFast2(CI, LOW); // CI is off
delayMicroseconds(6880); // 50% Duty Cycle
count++;
}
}
And this:-
while (count < 1000 ) // Need 1000 counts
digitalWriteFast2(FDCS, HIGH); // Turn FDCS on 12v
sets the pin high once, then cycles another 999 times doing nothing.
I haven't looked more closely yet, because I'm not 100% sure what you really want.
Describe clearly exactly what should happen please.
Edit: OK, I see you've now described what you want. I'll take a closer look.....
No problem. I think it's what you want - two staggered square waves with 50% duty-cycle.
And I'm in Australia - we don't celebrate Thanksgiving, but thanks for the thought anyway.
Yes.
It still compiles fine either way though. I had the library in "\Sketchbook\libraries", where additional 3rd party libs should be placed, and it was found and compiled without problems.
I'm attempting to add an LCD so that it will show "TEST READY" before buttonState = HIGH. After button is pressed the LCD will count down from 1000 then show "TEST FINISHED". Please take a look. Thank you!
//Powerstroke Diesel Flow Bench Controller
#include <digitalWriteFast.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int FDCS = 13; // Fuel Delivery Control Signal
const int CI = 10; // Cylinder Identification
const int buttonPin = 2; // Start Button
int buttonState = LOW; // Button is off
int count;
void setup()
{
lcd.begin(16, 2);
lcd.print("TEST READY"); // Waiting for button press
pinMode(FDCS, OUTPUT); // Fuel Delivery Control Signal
pinMode(CI, OUTPUT); // Cylinder Identification
pinMode(buttonPin, INPUT); // Start Button
digitalWriteFast2(FDCS, LOW);
digitalWriteFast2(CI, LOW);
}
void loop()
{
buttonState = digitalReadFast2(buttonPin); // Read Start Button State
if (buttonState == HIGH) // Button is pressed
{
while (count < 1000 ) // Need 1000 counts
{
digitalWriteFast2(FDCS, HIGH); // Turn FDCS on 12v
delayMicroseconds(1720); // Stay on
digitalWriteFast2(CI, HIGH); // Turn CI on 12v
delayMicroseconds(6880); // Stay on
digitalWriteFast2(FDCS, LOW); // FDCS is off
delayMicroseconds(1720); // 50% Duty Cycle
digitalWriteFast2(CI, LOW); // CI is off
delayMicroseconds(6880); // 50% Duty Cycle
count++;
lcd.print(count--);
}
if (count > 1000 )
lcd.print("TEST FINISHED"); // LCD after loop is complete
tone(9, 1000, 5000); // 1000hz tone for 5 seconds
}
}
That's not the right way. You posted the sketch twice, we don't know which one you mean. Also, now all the replies made by other people seem to not apply, which is confusing. Please just repost a new sketch in future. Which one did you update?
Also please tell us the results of the update. Does it work? Yes/no? Why? Issues?
aarg:
That's not the right way. You posted the sketch twice, we don't know which one you mean. Also, now all the replies made by other people seem to not apply, which is confusing. Please just repost a new sketch in future. Which one did you update?
Also please tell us the results of the update. Does it work? Yes/no? Why? Issues?
My apologies, I was trying to keep the thread clean. Please look at the last sketch. Thank you.