How to change modes

Pot twiddling worked to change the modes.

And yes, one "I see that button!" is printing per press.

I will employ the changes you just suggested and report back in a bit..

To me it is like it doesn't hear anything coming out of PIN 9...

I have multiples of the LED device I am trying to use, so I tried a new one, and same result incase I messed the previous up.... so no dice yet. Perhaps I need to msg @Jesper87 who got his similar device working, although the full code was never posted.

And just to show one more time... A 10k POT perfectly changes through the four modes of my LED "Servo" device using sweep code:

So, I am puzzled as to why alto's and everyone elses efforts have not solved my issue of the button not working. Thank you to all who tried to help me and continue to try. Look forward to your future posts.

Confirm that when you are using the potentiometer you are twisting and untwisting, so to speak, and each time you twist/untwist the numbers therefore go from something nearer to zero to something nearer to 1023 (or mapped nearer to 180).

Confirm that when you have untwisted, that is to say you have returned the potentiometer to the resting extreme of its travel, the servo or pot value is near zero.

Logically the button should do the same! I cannot accept that we are hanging up on exact angles being hit at a fussy rate.

Changing this if statement should align it with exactly what @Jesper87 claims worked:

// and is now being pressed
    if (isPressed) {
      Serial.println("I see that button!");
// it must have just went down, so do the servo thing
      myServo.writeMicroseconds(2000);
      delay(20);
      myServo.writeMicroseconds(1000);
    }

Again, I don't think it should matter, but it's an easy enough thing to try.

a7

I confirm your first two questions. #1 goes to 1022. #2 goes down to 1 and zero at times. As my previous video shows as well in #48. This HAS to be able to work with a button...please stick with me tonight.....

I will try changing the if statement as suggested.

It is working somewhat!@!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! pics and vids to follow...........very excited...........the button is working!!

Here is the proof that the BUTTON works:

Code used:

# include <Servo.h> 

int buttonPin = A0;
int servoPin = 9;

Servo myServo;

void setup() {
  Serial.begin(9600);

  pinMode(buttonPin, INPUT_PULLUP);   // wire button between pin and ground; no resistor

  myServo.attach(servoPin);
  myServo.write(0);         // r/c switch OFF
}

bool lastPressed;  // was the button down last time we looked?

void loop() {
  
  bool isPressed = digitalRead(buttonPin) == LOW;

// if the button is different to last time
  if (lastPressed != isPressed) {
// and is now being pressed
    if (isPressed) {
      Serial.println("I see that button!");
// it must have just went down, so do the servo thing
      myServo.writeMicroseconds(2000);
      delay(50);
      myServo.writeMicroseconds(1000);
    }
    lastPressed = isPressed;
  }

  delay(25);    // poor man's debounce
}

not sure why i have to press the button so many times to change the modes....delays?

Ok, for those who are following, here is the sketch that works perfectly. Meaning, one press of the button changes to the next mode:

# include <Servo.h> 

int buttonPin = A0;
int servoPin = 9;

Servo myServo;

void setup() {
  Serial.begin(9600);

  pinMode(buttonPin, INPUT_PULLUP);   // wire button between pin and ground; no resistor

  myServo.attach(servoPin);
  myServo.write(0);         // r/c switch OFF
}

bool lastPressed;  // was the button down last time we looked?

void loop() {
  
  bool isPressed = digitalRead(buttonPin) == LOW;

// if the button is different to last time
  if (lastPressed != isPressed) {
// and is now being pressed
    if (isPressed) {
      Serial.println("I see that button!");
// it must have just went down, so do the servo thing
      myServo.writeMicroseconds(2000);
      delay(60);
      myServo.writeMicroseconds(1000);
    }
    lastPressed = isPressed;
  }

  delay(25);    // poor man's debounce
}

Thank you to all who helped, especially @Alto777. Thank you so much. Talk to you all soon again.

Please do.

It is surprising that the length of the pulse create by the button is so critical. If I'm following your experiments and the results, 20 milliseconds did not work and 100 did not work.

Anyone who finds this thread as they may also find @Jesper87's would be well-advised to tinker with the delay that informs the pulse length.

And maybe take the experiments a bit further and fill in the corners of this a bit more.

Now I want to buy one of those things…

a7

So next I would like to have total of 8 of these LED "servo" devices running off this Nano at the same time controlled by one button. I think it will work just fine since they are not actually servos using massive power, just blinking LEDs.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.