// declare and initialize pins const int ledstripPin = 0;// the number of the LED strip pin const int dirPin = 1; // direction const int stepPin = 2; // step const int enaPin = 3; // enable String msg; float brightness; int brightness_analog; // the setup function runs once when you press reset or power the board void setup() { // initialize pins as outputs pinMode(ledstripPin, OUTPUT); pinMode(stepPin,OUTPUT); pinMode(dirPin,OUTPUT); pinMode(enaPin,OUTPUT); analogWrite(ledstripPin, 0); digitalWrite(dirPin,HIGH); // Set the rotation to one particular direction digitalWrite(enaPin,LOW); // Enable the motor to rotate Serial.begin(115200); // Start serial communication while (!Serial); // Wait until Serial is open Serial.println('listening...'); // Send that Serial is open and listening } // the loop function runs over and over again forever void loop() { while (Serial.available()) { delay(3); //delay to allow buffer to fill if (Serial.available() > 0) { char c = Serial.read(); //gets one byte from serial buffer msg += c; //makes the string readString } } if (msg != ""){ Serial.println("Echo: " + msg); if (msg.startsWith("B")){ brightness = msg.substring(1).toFloat(); Serial.println(brightness); brightness_analog = (int)((255.0*brightness/100.0)+0.5); Serial.println(brightness_analog); analogWrite(ledstripPin, brightness_analog); } else if (msg.startsWith("Step")){ // Perform a step by generating a single pulse digitalWrite(stepPin,HIGH); delayMicroseconds(350); digitalWrite(stepPin,LOW); delayMicroseconds(350); } else if (msg.startsWith("START")){ // start recording } else if (msg.startsWith("STOP")){ analogWrite(ledstripPin, 0); // Stop recording } msg = ""; } }