#include <FastLED.h>
#include <Stepper.h>

const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution for your motor

// Initialize the stepper motor with the number of steps and pins connected to it
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);


//   P5JS   ------------------------------
int posture; // P5JS

//   LEDS   ------------------------------
// Define the number of LEDs in the strip and the pin connected to it
#define NUM_LEDS 60
#define DATA_PIN 12 // Change this to pin 12
CRGB leds[NUM_LEDS];
//   LEDS   ------------------------------


void setup() {


  // set the speed at 60 rpm:
  myStepper.setSpeed(60);
  Serial.begin(9600); // P%JS

  // Initialize LED strip
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);

  // You can change the speed as needed
}

void loop() {

  /// P5JS---------------
  // Change LED color based on brightness value received from Serial
  if (Serial.available() > 0) {
    posture = Serial.read(); // Read brightness value from Serial
    if (posture == 0) { // Check if brightness is 0
      // Change LED color to blue
      fill_solid(leds, NUM_LEDS, CRGB::Blue);
      FastLED.show();
      myStepper.step(stepsPerRevolution);
      delay(50);
     
      }

    } else if (posture == 1) { // Check if brightness is 1
      // Change LED color to red
      fill_solid(leds, NUM_LEDS, CRGB::Red);
      FastLED.show();

        myStepper.step(-stepsPerRevolution);
  delay(50);
      /// P5JS-----------------
    }
  }
