I uploaded this code and the stepper motor is not rotated anymore. This code is about to open the green LED, rotate the stepper motor, and RGB light sensor start detected. Then, of RGB light sensor detect green (value = 65535) the motor will stop. The result is the RGB light sensor and LED are working but the stepper motor is not working anymore (not rotate).
But I try to up the code that write only about stepper motor to rotate and it work.
Here is my code
#include <Wire.h>
#include "SparkFunISL29125.h"
#include <Stepper.h>
SFE_ISL29125 RGB_sensor;
const int stepsPerRevolution = 12 ;
Stepper myStepper(stepsPerRevolution, 14, 12, 13, 15);
int stepCount = 0;
//Green
const byte ledg_gpio = 32;
//Blue
const byte ledb_gpio = 35;
void setup(){
//Initialize serial communication
Serial.begin(115200);
//Initialize ISl29125
RGB_sensor.init();
//Green LED
pinMode(ledg_gpio, OUTPUT);
//Blue LED
pinMode(ledb_gpio, OUTPUT);
}
void setZeroPosition(){
unsigned long previousMillis = 0;
const long interval = 1000;
unsigned long currentMillis = millis();
digitalWrite(ledg_gpio, HIGH);
myStepper.setSpeed(500);
myStepper.step(1);
bool motor_state = true;
while (motor_state) {
unsigned int green = RGB_sensor.readGreen();
Serial.println(green,DEC);
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (green == 65535){
motor_state = false;
}
myStepper.step(0);
digitalWrite(ledg_gpio, LOW);
}
}
}
void loop(){
setZeroPosition();
}