Errors with first sketch

Hi,

I haven't been able to fix the errors on my own. There are many errors, and I'm not sure where to start. Please take a look. Thank you!

#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 buttonState = 0;   
int count = 0;

void setup() {
  buttonState = digitalRead(buttonPin); // Read Start Button State
  pinMode(FDCS, OUTPUT); // Fuel Delivery Control Signal
  pinMode(CI, OUTPUT); // Cylinder Identification
  pinMode(buttonPin, INPUT); // Start Button
}

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
  if  else
  digitalWriteFast2(FDCS, LOW); // FDCS is off
  delayMicroseconds(1720); // 50% Duty Cycle
  digitalWriteFast2(CI, LOW); // CI is off
  delayMicroseconds(6880); // 50% Duty Cycle
  count++; 
}

What are the errors?

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:-

digitalWrite(FDCS, LOW);
digitalWrite(CI,LOW);

If so, do this in "setup()".

Hello,

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.

You've decared buttonPin twice too, as per the other two. It's an input, so you don't want to write "LOW" to it. Your button determines it's state.

There are other problems too. I'm just checking it out properly now, trying to make it compile before going further.

Having downloaded and installed the library in "libraries", you need to add this to the top of your program:-

#include "digitalWriteFast.h"

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.....

So if I understand you correctly, this is more or less what you want.
It compiles fine:-

//Powerstroke Diesel Flow Bench Controller

#include "digitalWriteFast.h"

const int FDCS = 13;                            // Fuel Delivery Control Signal
const int CI = 12;                              // Cylinder Identification
const int buttonPin = 2;                        // Start Button
int buttonState = LOW;
int count;

void setup()
{
    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()
{
    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++;
        }
        count = 0;
    }
}

Ignore my last post, since I didn't know what you wanted when I posted it.

I think so. Thank you so much for your help! I look forward to using and building upon this code. Happy Thanksgiving!

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. :slight_smile:

#include "digitalWriteFast.h"

If the library is in the libraries folder rather than the same folder as the program shouldn't this more properly be

#include <digitalWriteFast.h>

Yes. :slight_smile:
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
    }
}

          lcd.print(ctr -1);You never change the value of ctr so what do you expect this to print if not 999 ?

I updated the sketch and it compiles. Did I do it correct?

            count++;
            itoa(!count, outputCount, 10);      // Counter -1 for each loop
            lcd.print(outputCount);

Why not just count down from 1000 using count--; and print count ?

I updated sketch. Please take a look.

N2GN2:
I updated sketch. Please take a look.

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.

N2GN2:
My apologies, I was trying to keep the thread clean. Please look at the last sketch. Thank you.

With what in mind? You didn't answer my question.

I was trying to not post so many sketches.