I write the code and cause some problems
when I run this code the motor is doesn't work ( I mean the speed of motor is change more slowly) and RGB light sensor doesn't work ( mean the light intensity value from sensor is incorrect) .
Then, I try to check by run the code separately and the motor and sensor are work.
The problem is when I combine both code (motor and sensor), turn out it doesn't work.
Code working:
1.The stepper motor rotate and green LED turn on
2.RGB light sensor start detect
3.If light intensity detect green color (light intensity = 65535 = green), the motor will stop
#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 loop()
{
myStepper.setSpeed(500);
myStepper.step(1);
digitalWrite(ledg_gpio, HIGH);
//Find green
unsigned int green = RGB_sensor.readGreen();
Serial.println(green,DEC);
delay(1000);
//Blue LED
if(green = 65535)
{
//Motor stop
myStepper.step(0);
digitalWrite(ledg_gpio, LOW);
}
}