Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <AFMotor.h>
- AF_DCMotor infan(1, MOTOR12_1KHZ);
- AF_DCMotor exfan(2, MOTOR12_1KHZ);
- AF_DCMotor light(3, MOTOR12_1KHZ);
- double cur_time = 0;
- double time_correct = 0;
- double sunrise_time;
- double sunset_time;
- boolean infanState = false;
- boolean exfanState = false;
- boolean lightState = false;
- void setup() {
- Serial.begin(9600);
- Serial.println("No parameters set! Press '?' for a list of commands");
- infan.setSpeed(255);
- exfan.setSpeed(255);
- light.setSpeed(255);
- }
- void loop() {
- if(Serial.available()) {
- char in = Serial.read();
- if(in == '?') {
- printCommands();
- }
- else if(in == 'F' || in == 'f') {
- fanMenu();
- }
- else if (in == 'L' || in == 'l') {
- lightMenu();
- }
- else if (in == 'S' || in == 's') {
- setupMenu();
- }
- else {
- Serial.println("Unknown command. Press '?' for a list of commands");
- }
- }
- if(infanState) {
- infan.run(FORWARD);
- }
- else {
- infan.run(RELEASE);
- }
- if(exfanState) {
- exfan.run(FORWARD);
- }
- else {
- exfan.run(RELEASE);
- }
- if(lightState && sunrise_time != 0 && sunset_time != 0) {
- light.run(FORWARD);
- }
- else {
- light.run(RELEASE);
- }
- cur_time = millis() * 3600000;
- }
- void fanMenu() {
- Serial.println("Fan menu");
- Serial.print("Intake fan state: ");
- boolToOnOff(infanState);
- Serial.print("Exhaust fan state: ");
- boolToOnOff(exfanState);
- Serial.println("Press '1' to change state of intake fan");
- Serial.println("Press '2' to change state of exhaust fan");
- Serial.println("Press '0' to exit menu");
- int waittime1 = 0;
- while (true) {
- if(Serial.available()) {
- char serIn = Serial.read();
- if(serIn == '1') {
- infanChange();
- goto bailout;
- }
- else if(serIn == '2') {
- exfanChange();
- goto bailout;
- }
- else if(serIn == '0') {
- goto bailout;
- }
- else {
- Serial.println("Unknown input!");
- }
- }
- }
- bailout:;
- Serial.println("Back to main menu");
- }
- void lightMenu() {
- Serial.println("Light menu");
- if(sunrise_time == 0 || sunset_time == 0) {
- Serial.println("Light settings not configured! Light cannot be enabled");
- }
- else {
- Serial.print("Sunrise time: ");
- Serial.println(sunrise_time);
- Serial.print("Sunset time: ");
- Serial.println(sunset_time);
- }
- Serial.print("Current time: ");
- Serial.println(cur_time);
- Serial.println("Press 1 to configure sunrise time");
- Serial.println("Press 2 to configure sunset time");
- Serial.println("Press 3 to establish current time");
- Serial.println("Press 0 to return to main menu");
- while(true) {
- if(Serial.available()) {
- char serIn = Serial.read();
- if(serIn == '1') {
- configureSunrise();
- }
- else if(serIn == '2') {
- configureSunset();
- }
- else if (serIn == '3') {
- configureTime();
- }
- else if (serIn == '0') {
- goto breakout2;
- }
- else {
- Serial.println("Unknown command");
- }
- }
- }
- breakout2:;
- Serial.println("Returning to main menu");
- }
- void configureSunrise() {
- Serial.println("Please enter time for 'sunrise': ");
- Serial.println("Use format HH");
- while(!Serial.available()) {}
- double tempRise = 0;
- int serIn = Serial.read();
- if(serIn <= 48 && serIn >= 57) {
- tempRise = serIn * 10;
- }
- else {
- Serial.println("Unknown entry!");
- }
- serIn = Serial.read();
- if(serIn <= 48 && serIn >= 57) {
- sunrise_time = tempRise + serIn;
- }
- }
- void configureSunset() {
- }
- void configureTime() {
- }
- void setupMenu() {
- }
- void boolToOnOff(boolean in) {
- if(in) {
- Serial.println("On");
- }
- else {
- Serial.println("Off");
- }
- }
- void infanChange() {
- if(infanState) {
- infanState = false;
- Serial.println("Intake fan disabled");
- }
- else {
- infanState = true;
- Serial.println("Intake fan enabled");
- }
- }
- void exfanChange() {
- if(exfanState) {
- exfanState = false;
- Serial.println("Exhaust fan disabled");
- }
- else {
- exfanState = true;
- Serial.println("Exhaust fan enabled");
- }
- }
- void printCommands() {
- Serial.println("List of commands:");
- Serial.println("F: Go to fan menu");
- Serial.println("L: Go to lighting menu");
- Serial.println("S: Enter setup");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement