Question: can you guys fix this the following code... it is an Arduino code. just put the terms and syntax in order just format its syntax

can you guys fix this the following code... it is an Arduino code. just put the terms and syntax in order

just format its syntax and add comments to code ... rewrite some of the syntax if you think how that works.

.... no need to run it

//Imports the BitVoicer library to the sketch #include //Instantiates the BitVoicerSerial class BitVoicerSerial bvSerial = BitVoicerSerial(); //Stores the data type retrieved by getData() byte dataType = 0; //Stores the state of pin 4 byte pinVal = 0;

#define IN1 8 #define IN2 9 #define IN3 10 #define IN4 11 int Steps = 0; boolean Direction = true;// gre unsigned long last_time; unsigned long currentMillis ; int steps_left=4095; long time;

void setup() { //Starts serial communication at 9600 bps Serial.begin(9600); pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT); pinMode(IN3, OUTPUT); pinMode(IN4, OUTPUT); //Sets digital pin 4 as OUTPUT pinMode(4, OUTPUT); //Turns off pin 4 digitalWrite(4, pinVal); } void loop() { // read bitvoicer stuff

while(steps_left>0){ currentMillis = micros(); if(currentMillis-last_time>=1000){ stepper(1); time=time+micros()-last_time; last_time=micros(); steps_left--; } } Serial.println(time); Serial.println("Wait...!"); delay(2000); Direction=!Direction; steps_left=4095; }

void stepper(int xw){ for (int x=0;x switch(Steps){ case 0: digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); digitalWrite(IN3, LOW); digitalWrite(IN4, HIGH); break; case 1: digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); digitalWrite(IN3, HIGH); digitalWrite(IN4, HIGH); break; case 2: digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW); break; case 3: digitalWrite(IN1, LOW); digitalWrite(IN2, HIGH); digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW); break; case 4: digitalWrite(IN1, LOW); digitalWrite(IN2, HIGH); digitalWrite(IN3, LOW); digitalWrite(IN4, LOW); break; case 5: digitalWrite(IN1, HIGH); digitalWrite(IN2, HIGH); digitalWrite(IN3, LOW); digitalWrite(IN4, LOW); break; case 6: digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW); digitalWrite(IN3, LOW); digitalWrite(IN4, LOW); break; case 7: digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW); digitalWrite(IN3, LOW); digitalWrite(IN4, HIGH); break; default: digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); digitalWrite(IN3, LOW); digitalWrite(IN4, LOW); break; } SetDirection(); } } void SetDirection(){ if(Direction==1){ Steps++;} if(Direction==0){ Steps--; } if(Steps>7){Steps=0;} if(Steps<0){Steps=7; } }

//This function runs every time serial data is available //in the serial buffer after a loop void serialEvent() { //Reads the serial buffer and stores the received data type dataType = bvSerial.getData();

//Checks if the data type is the same as the one in the //Voice Schema if (dataType == BV_BYTE) { //Checks the stored value in byteData by getData() and //changes the value of the pin if (bvSerial.byteData == 0) pinVal = LOW; else pinVal = HIGH; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!