Go Down

Topic: using pullstime  (Read 1 time) previous topic - next topic

Matyk

However I think that the only thing I do not have a spare of is the problem, UKHeliBob I know it is kind of a stupid request from me, but do you think that you could finish the code so that it works? I know that I sound like the most entitled idiot, but it will be a while before I´ll get a new Arduino and then again you saw how much I struggled, which I kind of sensed that I was really getting on your nerve. If you don´t finish the code, I get it since it is a really entitled request from me and I hope that you don´t imagine me as a douche or something. It is that it would just take less time for me to finally get to the whole project testing, but anyway thanks!

UKHeliBob

Your code looks OK.

I have tidied it up the layout a little and added another debug print to show the value being written to m1 but the logic looks OK
Code: [Select]

#include <Servo.h>
Servo m1;
const byte buttonPin = A2;
const int ledPin = 9;
int writeValues[5] = {1000, 1250, 1500, 1750, 2000};
int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;

void setup()
{
  // initialize the button pin as a input:
  pinMode(buttonPin, INPUT_PULLUP);
  // initialize the LED as an output:
  pinMode(ledPin, OUTPUT);
  // initialize serial communication:
  Serial.begin(9600);
}

void loop()
{
  buttonState = digitalRead(buttonPin);
  if (buttonState != lastButtonState)
  {
    // if the state has changed, increment the counter
    if (buttonState == LOW)
    {
      // if the current state is HIGH then the button went from off to on:
      buttonPushCounter++;
      Serial.println(buttonPushCounter);
      Serial.print("buttonPushCounter % 5 = ");
      Serial.println(buttonPushCounter % 5);
      Serial.print("writing ");
      Serial.println(writeValues[buttonPushCounter % 5]);
    }
    else
    {
      // if the current state is LOW then the button went from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  lastButtonState = buttonState;
  m1.writeMicroseconds(writeValues[buttonPushCounter % 5]);
}
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Matyk

thanks so much dude, really. Have a great day! :-)

Matyk

for some reason, your code can´t compile it always says


Code: [Select]
error: scalar object 'writeValues' requires one element in initializer

 int writeValues = {1000, 1250, 1500, 1750, 2000};

                                                ^

exit status 1
scalar object 'writeValues' requires one element in initializer



Do  you know what to do, I don´t understand it

Matyk

For some reason when I do this :

int writeValues[5]  = {1000, 1250, 1500, 1750, 2000};

it compiles fine, is it because it didn´t have an array value or something?

Matyk

It still doesn´t upload, but still a huge thanks! :-)

UKHeliBob

For some reason when I do this :

int writeValues[5]  = {1000, 1250, 1500, 1750, 2000};

it compiles fine, is it because it didn´t have an array value or something?
The code that I posted had the [5] for the array in it.  See post #91.  I don't know what you did to it to remove it but I hope that it did not involve typing the code into the IDE.

Note that the code has nothing to do with whether it uploads to the Arduino or not.  One thing that you could do it is to uninstall the IDE and install it again.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Go Up