0

momentary button switch code
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: momentary button switch code

by billbishop on Mon Jul 15, 2019 8:57 pm

Changed that, still nothing from the motors, which work well when tested

billbishop
 
Posts: 44
Joined: Sun Jun 16, 2019 12:55 pm

Re: momentary button switch code

by adafruit_support_bill on Mon Jul 15, 2019 9:11 pm

What did you change it to? Please post your code.

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Re: momentary button switch code

by billbishop on Mon Jul 15, 2019 9:18 pm

void loop() {

blackButtonValue = digitalRead(BLACK_BUTTON_PIN);

if (blackButtonValue == HIGH)
{
myMotor1->step(100, FORWARD, SINGLE);
delay(2);
myMotor2->step(1024, FORWARD, SINGLE);
delay(2);

}
}

billbishop
 
Posts: 44
Joined: Sun Jun 16, 2019 12:55 pm

Re: momentary button switch code

by adafruit_support_bill on Mon Jul 15, 2019 9:22 pm

Add some Serial.println statements to print out the actual values you are getting from the digitalRead.
https://www.arduino.cc/reference/en/lan ... l/println/
Make sure that the values change when you press the button.

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Re: momentary button switch code

by billbishop on Mon Jul 15, 2019 9:43 pm

starting at 370 and going slowly down

billbishop
 
Posts: 44
Joined: Sun Jun 16, 2019 12:55 pm

Re: momentary button switch code

by billbishop on Mon Jul 15, 2019 9:44 pm

nothing as a result of pressing the button...I begin to suspect the physical buttons -

billbishop
 
Posts: 44
Joined: Sun Jun 16, 2019 12:55 pm

Re: momentary button switch code

by adafruit_support_bill on Tue Jul 16, 2019 6:38 am

starting at 370 and going slowly down

How are you getting 370 from a digitalRead? That function returns only HIGH (1) or LOW (0).

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Re: momentary button switch code

by billbishop on Tue Jul 16, 2019 7:53 am

LOL that was my question for you - I searched for a short, found none. I had added a resistor to each pin to ground based on advice from this thread. The resistors are still there. I put my tester on it and the readings were slow and all over the place. That is why I suspect a hardware problem. Now I'm considering a rebuild with the new shield that arrived here the other day..the shield currently in use has seen some hard times; perhaps that is the problem. I was also shocked when I saw the output, but, someone on your end surely can interpret what it was caused by?

billbishop
 
Posts: 44
Joined: Sun Jun 16, 2019 12:55 pm

Re: momentary button switch code

by adafruit_support_bill on Tue Jul 16, 2019 8:48 am

We can only guess because you have not posted the code that is outputting that value.

The return value of a digitalRead() is 0 or 1. It is not an analog value. If you are seeing 370, there is a problem with your code.

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Re: momentary button switch code

by billbishop on Tue Jul 16, 2019 8:49 am

I employed the code that was given to me here -

billbishop
 
Posts: 44
Joined: Sun Jun 16, 2019 12:55 pm

Re: momentary button switch code

by billbishop on Tue Jul 16, 2019 8:50 am

I also posted the code right here after I employed it.

billbishop
 
Posts: 44
Joined: Sun Jun 16, 2019 12:55 pm

Re: momentary button switch code

by adafruit_support_bill on Tue Jul 16, 2019 9:02 am

Nobody has posted any code to this thread with serial output.

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Re: momentary button switch code

by billbishop on Tue Jul 16, 2019 9:55 am

You're right, just a link to the serial code which gave me nothing new because I've been using the serial monitor for years. However, previous to the discussion on getting the serial readout, I was given a couple of small code corrections which I also employed. My point is that the readout I received from my serial monitor reveals something and someone working for adafruit should know what that something is.

billbishop
 
Posts: 44
Joined: Sun Jun 16, 2019 12:55 pm

Re: momentary button switch code

by billbishop on Tue Jul 16, 2019 10:20 am

Code: Select all | TOGGLE FULL SIZE

#include <Adafruit_MotorShield.h>
#include <Adafruit_MS_PWMServoDriver.h>

const int RESET_BUTTON_PIN = A1;
const int RED_BUTTON_PIN = A2;
const int BLACK_BUTTON_PIN = A3;

int resetButtonValue = LOW;
int blackButtonValue = LOW;
int redButtonValue = LOW;
int redDirection = -1;

Adafruit_MotorShield AFMS = Adafruit_MotorShield();

Adafruit_StepperMotor *myMotor1 = AFMS.getStepper(2048, 1);
Adafruit_StepperMotor *myMotor2 = AFMS.getStepper(2048, 2);

int analogValue = 0;

void setup() {

  Serial.begin(9600);

  AFMS.begin();

  myMotor1->setSpeed(15);
  myMotor2->setSpeed(15);

  pinMode(RESET_BUTTON_PIN, INPUT);
  pinMode(BLACK_BUTTON_PIN, INPUT);
  pinMode(RED_BUTTON_PIN, INPUT);

}

void loop() {
  analogValue = analogRead(0);

  Serial.println(analogValue);

  delay(10);

  blackButtonValue = digitalRead(BLACK_BUTTON_PIN);

  if (blackButtonValue == HIGH)
  {
    myMotor1->step(100, FORWARD, SINGLE);
    delay(2);
    myMotor2->step(1024, FORWARD, SINGLE);
    delay(2);

  }
}

billbishop
 
Posts: 44
Joined: Sun Jun 16, 2019 12:55 pm

Re: momentary button switch code

by adafruit_support_bill on Tue Jul 16, 2019 10:36 am

My point is that the readout I received from my serial monitor reveals something and someone working for adafruit should know what that something is.

We can only work with the information you provide to us. An output value means nothing if we can't see what produced it.

Code: Select all | TOGGLE FULL SIZE
  analogValue = analogRead(0);

  Serial.println(analogValue);


So you are talking an analog reading from pin A0.

Code: Select all | TOGGLE FULL SIZE
const int RESET_BUTTON_PIN = A1;
const int RED_BUTTON_PIN = A2;
const int BLACK_BUTTON_PIN = A3;


But your buttons are connected to pins A1, A2 and A3 ?

If there is nothing connected to A0, then the value you are reading and printing out is unrelated to the state of your buttons or the operation of your motors.

If you want to diagnose the problem with this code:
Code: Select all | TOGGLE FULL SIZE
  blackButtonValue = digitalRead(BLACK_BUTTON_PIN);

  if (blackButtonValue == HIGH)
  {
    myMotor1->step(100, FORWARD, SINGLE);
    delay(2);
    myMotor2->step(1024, FORWARD, SINGLE);
    delay(2);

  }


You need to know the state of BLACK_BUTTON_PIN.

You can do that by printing out blackButtonValue.

Code: Select all | TOGGLE FULL SIZE
  blackButtonValue = digitalRead(BLACK_BUTTON_PIN);
  Serial.println(blackButtonValue);

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.


cron