User:Rhorton4549/enes100/Wind Tunnel/Code

esc_easy
// i used this code to find the pulse width for the esc. // to use it you have turn on the esc after you enter in s the change the speed down to 0 and that will //set the esc's range and and will allow the esc to speed up or down. Now esch esc will have a diffrent speed range and //you will have to find it.
 * 1) include 

Servo myservo; int tspeed=90; //start speed int start=0;

void arm{ // arm the speed controller, modify as necessary for your ESC setSpeed(0); delay(1000); }

void setSpeed(int speed){ //these are the values you change ie: 60,180 or 30,180 //I used 85 to 180 becuase it gave me speed from the values 65(off) to 90 and i wanted a 25 speed gradient int pulse = map(speed, 0, 100,85, 180); myservo.write(pulse); }

void setup { Serial.begin(9600); Serial.println("Wait for your input! [s] to init..."); while(Serial.available <= 0) delay(1000); int incomingByte = Serial.read;

Serial.println("Start the system..."); myservo.attach(9); arm; delay(1000); Serial.println("Set Speed"); }

void loop { if(start==0){ setSpeed(tspeed); start=1; }else{ if(Serial.available > 0) { int incomingByte = Serial.read; if(incomingByte == 43)     // sends the character '+' tspeed++;                 // increases the speed else if(incomingByte == 45) // sends the character '-' tspeed--;                 // decreases the speed else if(incomingByte == 44) tspeed=tspeed-10;     //sends character ',' else if(incomingByte == 46) tspeed=tspeed+10;     // sends character '.' else if(incomingByte == 48) // sends the character '0' tspeed = 0;               // set the speed to zero else tspeed=incomingByte; if(tspeed < 0) tspeed = 0; if(tspeed > 100) tspeed = 100; Serial.print("speed is "); Serial.println(tspeed); } }     setSpeed(tspeed); delay(500); }

esc
// this uses the Arduino servo library included with version 0012

// caution, this code sweeps the motor up to maximum speed ! // make sure the motor is mounted securily before running.


 * 1) include 

Servo myservo; int tspeed; //start speed

void arm{ // arm the speed controller, modify as necessary for your ESC setSpeed(0); delay(1000); //delay 1 second, some speed controllers may need longer }

void setSpeed(int speed){ // speed is from 0 to 100 where 0 is off and 100 is maximum speed //the following maps speed values of 0-100 to angles from 0-180, // some speed controllers may need different values, see the ESC instructions int pulse = map(speed, 0, 100,40, 180); myservo.write(pulse); }

void setup { Serial.begin(9600); Serial.println("Wait for your input! [s] to init..."); while(Serial.available <= 0) delay(1000); int incomingByte = Serial.read;

Serial.println("Start the system..."); myservo.attach(9); arm; // cycle; if(incomingByte == 115) { // s   Serial.println("Speed up Speed down"); cycle; //delay(1000); } Serial.println("Set Speed"); //Serial.println("Start loop..."); }

void cycle { int speed;

for(speed = 0; speed <= 100; speed += 10) { setSpeed(speed); delay(1000); } // sweep back down to 0 speed. for(speed = 95; speed > 0; speed -= 10) { setSpeed(speed); delay(1000); } }

void loop { if(Serial.available > 0) { int incomingByte = Serial.read; if(incomingByte == 43)     // sends the character '+' tspeed++;                 // increases the speed else if(incomingByte == 45) // sends the character '-' tspeed--;                 // decreases the speed else if(incomingByte == 44) tspeed=tspeed-10;     //sends character ',' else if(incomingByte == 46) tspeed=tspeed+10;     // sends character '.' else if(incomingByte == 48) // sends the character '0' tspeed = 0;               // set the speed to zero //   if(tspeed < 0) //     tspeed = 0; //   if(tspeed > 100) //     tspeed = 100; Serial.print("speed is "); Serial.println(tspeed); }    setSpeed(tspeed); delay(500); }