Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include "utilities.h"
- #include "io.hpp"
- #include <stdbool.h>
- #include "gpio.hpp"
- int main(void){
- typedef enum{IDLE, MORNING, OPEN, PAUSE} State;
- State currentState = IDLE;
- State tempState = currentState;
- int light_value = LS.getPercentValue();
- GPIO pin20(P1_20);
- pin20.setAsOutput();
- pin20.setLow();
- int temp1 = 1;
- printf("Start\n");
- while(1){
- //LD.setNumber(light_value);
- delay_ms(200);
- switch(currentState){
- case IDLE:
- while(temp1){
- printf("IDLE\n");
- printf("IDLE\n");
- if(SW.getSwitch(1)){
- currentState = MORNING;
- printf("After Declaring State");
- temp1=0;
- //break;
- }
- if(SW.getSwitch(2)){
- tempState = currentState;
- currentState = PAUSE;
- }
- }
- break;
- case MORNING:
- while(1){
- printf("Morning0\n");
- light_value = LS.getPercentValue();
- if(light_value<=50){
- currentState = OPEN;
- break;
- }
- if(SW.getSwitch(1)){
- currentState = IDLE;
- break;
- }
- if(SW.getSwitch(2)){
- tempState = currentState;
- currentState = PAUSE;
- break;
- }
- }
- break;
- case OPEN:
- while(1){
- light_value = LS.getPercentValue();
- if(light_value<50){
- //printf("SETHIGH");
- pin20.setHigh();
- }else{
- currentState = MORNING;
- break;
- }
- if(SW.getSwitch(1)){
- currentState = IDLE;
- break;
- }
- if(SW.getSwitch(2)){
- tempState = currentState;
- currentState = PAUSE;
- break;
- }
- }
- break;
- case PAUSE:
- while(1){
- if(SW.getSwitch(2)){
- currentState = tempState;
- break;
- }
- if(SW.getSwitch(1)){
- currentState = tempState;
- break;
- }
- if(SW.getSwitch(3)){
- currentState = tempState;
- break;
- }
- }
- break;
- /***
- *
- *
- pin20.setHigh();
- pin20.setLow();
- delay_ms(200);
- // Switch #1
- if(SW.getSwitch(1)) {
- LE.on(1);
- }
- else {
- LE.off(1);
- }
- //Switch #2
- if(SW.getSwitch(2)){
- int light_value = LS.getPercentValue();
- LD.setNumber(light_value);
- case CLOSE:
- if(light_value<50){
- //printf("SETHIGH");
- pin20.setHigh();
- }else{
- currentState = NIGHT;
- }
- if(SW.getSwitch(3)){
- tempState = currentState;
- currentState = PAUSE;
- }
- break;
- case NIGHT:
- light_value = LS.getPercentValue();
- if(light_value>=50){
- currentState = OPEN;
- }
- if(SW.getSwitch(2)){
- currentState = IDLE;
- }
- if(SW.getSwitch(1)){
- currentState = MORNING;
- }
- if(SW.getSwitch(3)){
- tempState = currentState;
- currentState = PAUSE;
- }
- break;
- }*////
- }
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement