float Voltage = 0; | |
float current = 0; // value read from the pot | |
float calculatedCurrent = 0; | |
int tilt = 0; | |
const int analogVoltageInPin = A0; // Analog input pin that the potentiometer is attached to | |
const int analogCurrentInPin = A1; // Analog input pin that the potentiometer is attached to | |
// the setup function runs once when you press reset or power the board | |
void setup() { | |
Serial.begin(9600); | |
// initialize digital pin 13 as an output. | |
pinMode(13, OUTPUT); | |
pinMode(analogVoltageInPin, INPUT); | |
pinMode(analogCurrentInPin, INPUT); | |
pinMode(4, OUTPUT); | |
pinMode(5, OUTPUT); | |
pinMode(6, OUTPUT); | |
pinMode(7, OUTPUT); | |
pinMode(8, INPUT_PULLUP); | |
pinMode(11, INPUT_PULLUP); | |
} | |
// the loop function runs over and over again forever | |
void loop() { | |
int switch1 = digitalRead(8); | |
int switch2 = digitalRead(11); | |
getVoltageCurrent(); | |
/* Serial.print(" - Switch 1: "); | |
Serial.print(switch1); | |
Serial.print(" - Switch 2: "); | |
Serial.println(switch2);*/ | |
if (switch1 == LOW) | |
{ | |
alwaysOn(); | |
} | |
else if (switch2 == LOW) | |
{ | |
sequentialOn(); | |
} | |
else | |
{ | |
turnOff(); | |
} | |
delay(250); | |
//Current = analogRead(analogCurrentInPin); | |
// Serial.println(tilt); | |
} | |
void alwaysOn(){ | |
digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level) | |
digitalWrite(5, HIGH); // turn the LED on (HIGH is the voltage level) | |
digitalWrite(6, HIGH); // turn the LED on (HIGH is the voltage level) | |
digitalWrite(7, HIGH); // turn the LED on (HIGH is the voltage level) | |
} | |
void sequentialOn(){ | |
digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level) | |
getVoltageCurrent(); | |
delay(2000); // wait for a second | |
digitalWrite(5, HIGH); // turn the LED on (HIGH is the voltage level) | |
getVoltageCurrent(); | |
delay(2000); // wait for a second | |
digitalWrite(6, HIGH); // turn the LED on (HIGH is the voltage level) | |
getVoltageCurrent(); | |
delay(2000); // wait for a second | |
digitalWrite(7, HIGH); // turn the LED on (HIGH is the voltage level) | |
getVoltageCurrent(); | |
delay(2000); // wait for a second | |
digitalWrite(4, LOW); // turn the LED off by making the voltage LOW | |
digitalWrite(5, LOW); // turn the LED off by making the voltage LOW | |
digitalWrite(6, LOW); // turn the LED off by making the voltage LOW | |
digitalWrite(7, LOW); // turn the LED off by making the voltage LOW | |
getVoltageCurrent(); | |
delay(500); // wait for a second | |
} | |
void turnOff() | |
{ | |
digitalWrite(4, LOW); // turn the LED off by making the voltage LOW | |
digitalWrite(5, LOW); // turn the LED off by making the voltage LOW | |
digitalWrite(6, LOW); // turn the LED off by making the voltage LOW | |
digitalWrite(7, LOW); // turn the LED off by making the voltage LOW | |
} | |
void getVoltageCurrent() | |
{ | |
current = 514.0-analogRead(analogCurrentInPin); | |
calculatedCurrent = current * 27.03 / 1023.0; | |
Voltage = analogRead(analogVoltageInPin); | |
// Serial.print("- Voltage: "); | |
Serial.print(Voltage); | |
Serial.print(","); | |
//Serial.print("- Current: "); | |
Serial.println(calculatedCurrent); | |
} | |
SpaceApps is a NASA incubator innovation program.