// 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 const int cameraPin = 8; // camera (same as UPDI) const int hallPin = 11; // hall sensor pin String msg; float brightness; int brightness_analog; float angle; // 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); pinMode(cameraPin,OUTPUT); digitalWrite(cameraPin,LOW); // Stop recording pinMode(hallPin,INPUT); analogWrite(ledstripPin, 0); digitalWrite(dirPin,LOW); // 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 != ""){ if (msg.startsWith("Step")){ // Perform a step by generating a single pulse digitalWrite(stepPin,HIGH); delayMicroseconds(200); digitalWrite(stepPin,LOW); delayMicroseconds(200); angle = 0.0; for (int i = 0; i < 5; i++){ angle = angle + (float) analogRead(hallPin); } Serial.println(angle/5); } else{ 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("START")){ digitalWrite(cameraPin,HIGH); // Start recording } else if (msg.startsWith("STOP")){ analogWrite(ledstripPin, 0); // Set brightness to zero digitalWrite(cameraPin,LOW); // Stop recording } } msg = ""; } }