We are currently trying to create a code allowing the arduino to go down for a certain amount of time run for a certain amount of time then repeat a few times. I copied and pasted the code so far below. If you have any suggestions I am all ears. I am currently able to display the pressure and the time on the monitor but the turbine is not running.
//To Do: Sensor Pin Constants
/* pin for turbine*/
#include <Servo.h>
byte servoPin = 9;
Servo servo;
/* Sensors */
const byte Clock = A4; //RV 3028 Clock using later when i learn it
const byte PressureSensor = A2; // Pressure sensor
// To Do: Variables for Timed Events
const unsigned long eventTime_1_Pressure = 5000; // interval in ms
const unsigned long eventTime_2_turbine = 10000; // interval in ms
unsigned long previousTime_1 = 0;
unsigned long previousTime_2 = 0;
void setup(){
// To Do: Serial communication
Serial.begin(9600);
servo.attach(servoPin);
servo.writeMicroseconds(1500); // send "stop" signal to ESC.
// delay to allow the ESC to recognize the stopped signal
}
void loop(){
/*shoing pressure*/
/* Updates frequently */
unsigned long currentTime = millis();//RV 3028
/* This is event 1 stuff *//*showing pressure*/
if( currentTime - previousTime_1 >= eventTime_1_Pressure ){
Serial.print ("Pressure: ");
Serial.println( analogRead(PressureSensor) ); /* displays the pressure*/
Serial.print ("Time: ");
Serial.println( millis());
/* Update the timing for the next event */
previousTime_1 = currentTime;
}
// To Do: Event 2 timing turning on motor
/* Updates frequently */
/* This is event 2 stuff */
if( currentTime - previousTime_2 >= eventTime_2_turbine ){
Serial.print ("Starting Turbine Speed Event 1: 1300 ");
{
unsigned long starttime = millis();
unsigned long endtime = 3000;
endtime = starttime;
while ((endtime - starttime) <=3000) // do this for 3 seconds
int signal = 1700; // Set signal value, which should be between 1100 and 1900
servo.writeMicroseconds(signal); // Send signal to ESC.
}
int signal = 1500; // Set signal value, this stops motor
servo.writeMicroseconds(signal); // Send signal to ESC.
}
}
previousTime_2 = currentTime;
}