[ESP32] when run two code together, it doesn't work

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);   
  }

}

if (green == 65535)

'uint16_t readGreen();'

ReadGreen returns a unit16. What is the highest number a 16 bit int can hold?

OMG Thank you

The the highest number is 65536.

But I try it several time, the maximum intensity value from sensor is 65535.

You have declared unsigned int green so the possible values range is from 0 to 65535

What is the highest number a unit16 can hold?

65536

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