Skip to main content
added 12 characters in body; edited title
Source Link
ocrdu
  • 1.8k
  • 3
  • 11
  • 24

blink Blink LED without delay with stepper motor

Based on a former question (Stepper motor and blink LEDprevious question) I modified tothe script to use blink without delay. 

Unfortunately, it does not work, any idea waywhy? I

I am using SparkFun RedBoard Plus, Qwiic LED Stick - APA102C, Adafruit Stepper motor - NEMA-17 size - 200 steps/rev and Adafruit Motor Shield V2 Thanks.

blink LED without delay with stepper motor

Based on a former question (Stepper motor and blink LED) I modified to script to use blink without delay. Unfortunately, it does not work, any idea way? I am using SparkFun RedBoard Plus, Qwiic LED Stick - APA102C, Adafruit Stepper motor - NEMA-17 size - 200 steps/rev and Adafruit Motor Shield V2 Thanks

Blink LED without delay with stepper motor

Based on a previous question I modified the script to use blink without delay. 

Unfortunately, it does not work, any idea why?

I am using SparkFun RedBoard Plus, Qwiic LED Stick - APA102C, Adafruit Stepper motor - NEMA-17 size - 200 steps/rev and Adafruit Motor Shield V2.

added 39 characters in body
Source Link

Modified code (based on @Michel Keijzers, see below):

Modified code:

Modified code (based on @Michel Keijzers, see below):

added 2035 characters in body
Source Link

Modified code:

#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "Qwiic_LED_Stick.h" // Click here to get the library: http://librarymanager/All#SparkFun_Qwiic_LED_Stick

// Variables will change:
int ledState = LOW;             // ledState used to set the LED

unsigned long previousMillis = 0;        // will store last time LED was updated

// constants won't change:
const long interval = 500;           // interval at which to blink (milliseconds)

LED LEDStick; //Create an object of the LED class

Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);

void setup() {
  Wire.begin();
  Serial.begin(115200);
  while (!Serial);
  Serial.println("Stepper test!");



  if (!AFMS.begin()) {
    // if (!AFMS.begin(1000)) {
    Serial.println("Could not find Motor Shield. Check wiring.");
    while (1);
  }
  Serial.println("Motor Shield found.");
  myMotor->setSpeed(50);  // 50 rpm


  //Start up communication with the LED Stick
  if (!LEDStick.begin())  {
    Serial.println("Qwiic LED Stick failed to begin. Please check wiring and try again!");
    while (1);
  }

  Serial.println("Qwiic LED Stick ready!");
//  LEDStick.setLEDColor(255, 0, 0);
  LEDStick.setLEDBrightness(1);
}

void loop() {
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    ledState = !ledState;
    // set the LED with the ledState of the variable:
    uint8_t intensity = ledState == HIGH ? 255 : 0;
    LEDStick.setLEDColor(intensity, intensity, intensity);
  }

  Serial.println("Single coil steps");
  myMotor->step(200, FORWARD, SINGLE);
}

Code:

Code:

Modified code:

#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "Qwiic_LED_Stick.h" // Click here to get the library: http://librarymanager/All#SparkFun_Qwiic_LED_Stick

// Variables will change:
int ledState = LOW;             // ledState used to set the LED

unsigned long previousMillis = 0;        // will store last time LED was updated

// constants won't change:
const long interval = 500;           // interval at which to blink (milliseconds)

LED LEDStick; //Create an object of the LED class

Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);

void setup() {
  Wire.begin();
  Serial.begin(115200);
  while (!Serial);
  Serial.println("Stepper test!");



  if (!AFMS.begin()) {
    // if (!AFMS.begin(1000)) {
    Serial.println("Could not find Motor Shield. Check wiring.");
    while (1);
  }
  Serial.println("Motor Shield found.");
  myMotor->setSpeed(50);  // 50 rpm


  //Start up communication with the LED Stick
  if (!LEDStick.begin())  {
    Serial.println("Qwiic LED Stick failed to begin. Please check wiring and try again!");
    while (1);
  }

  Serial.println("Qwiic LED Stick ready!");
//  LEDStick.setLEDColor(255, 0, 0);
  LEDStick.setLEDBrightness(1);
}

void loop() {
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    ledState = !ledState;
    // set the LED with the ledState of the variable:
    uint8_t intensity = ledState == HIGH ? 255 : 0;
    LEDStick.setLEDColor(intensity, intensity, intensity);
  }

  Serial.println("Single coil steps");
  myMotor->step(200, FORWARD, SINGLE);
}

Code:

Source Link
Loading