Advertisement
whitesurge

Fixed it!

Dec 4th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.26 KB | None | 0 0
  1. #include <stdio.h>
  2. #include "utilities.h"
  3. #include "io.hpp"
  4. #include <stdbool.h>
  5. #include "gpio.hpp"
  6.  
  7.  
  8.  
  9. int main(void){
  10.     typedef enum{IDLE, MORNING, OPEN, PAUSE} State;
  11.  
  12.  
  13.     State currentState = IDLE;
  14.     State tempState = currentState;
  15.     int light_value = LS.getPercentValue();
  16.     GPIO pin20(P1_20);
  17.     pin20.setAsOutput();
  18.     pin20.setLow();
  19.     int temp1 = 1;
  20.     printf("Start\n");
  21.  
  22.     while(1){
  23.  
  24.  
  25.         //LD.setNumber(light_value);
  26.         delay_ms(200);
  27.  
  28.         switch(currentState){
  29.  
  30.             case IDLE:
  31.                     printf("IDLE\n");
  32.                     printf("IDLE\n");
  33.                     if(SW.getSwitch(1)){
  34.                         currentState = MORNING;
  35.                         printf("After Declaring State");
  36.  
  37.                     }
  38.                     if(SW.getSwitch(2)){
  39.                         tempState = currentState;
  40.                         currentState = PAUSE;
  41.                     }
  42.                
  43.                 break;
  44.  
  45.  
  46.             case MORNING:
  47.                     printf("Morning0\n");
  48.                     light_value = LS.getPercentValue();
  49.                     if(light_value<=50){
  50.                         currentState = OPEN;
  51.                        
  52.                     }
  53.                     if(SW.getSwitch(1)){
  54.                         currentState = IDLE;
  55.                        
  56.                     }
  57.                     if(SW.getSwitch(2)){
  58.                         tempState = currentState;
  59.                         currentState = PAUSE;
  60.                     }
  61.  
  62.                
  63.                 break;
  64.  
  65.  
  66.  
  67.             case OPEN:
  68.                     light_value = LS.getPercentValue();
  69.                     if(light_value<50){
  70.                         //printf("SETHIGH");
  71.                         pin20.setHigh();
  72.                     }else{
  73.                         currentState = MORNING;
  74.                        
  75.                     }
  76.  
  77.                     if(SW.getSwitch(1)){
  78.                         currentState = IDLE;
  79.                        
  80.                     }
  81.                     if(SW.getSwitch(2)){
  82.                         tempState = currentState;
  83.                         currentState = PAUSE;
  84.                        
  85.                     }
  86.                
  87.                 break;
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.             case PAUSE:
  97.                     if(SW.getSwitch(2)){
  98.                         currentState = tempState;
  99.                        
  100.                     }
  101.                     if(SW.getSwitch(1)){
  102.                         currentState = tempState;
  103.                        
  104.                     }
  105.                     if(SW.getSwitch(3)){
  106.                         currentState = tempState;
  107.                        
  108.                     }
  109.                
  110.                 break;
  111.  
  112.  
  113.  
  114.  
  115.  
  116.                 /***
  117.                  *
  118.                  *
  119.  
  120.  
  121.             pin20.setHigh();
  122.             pin20.setLow();
  123.  
  124.             delay_ms(200);
  125.             // Switch #1
  126.             if(SW.getSwitch(1)) {
  127.                 LE.on(1);
  128.             }
  129.             else {
  130.                 LE.off(1);
  131.             }
  132.  
  133.             //Switch #2
  134.  
  135.             if(SW.getSwitch(2)){
  136.                 int light_value = LS.getPercentValue();
  137.                 LD.setNumber(light_value);
  138.  
  139.         case CLOSE:
  140.                 if(light_value<50){
  141.                         //printf("SETHIGH");
  142.                     pin20.setHigh();
  143.                 }else{
  144.                     currentState = NIGHT;
  145.                         }
  146.                 if(SW.getSwitch(3)){
  147.                     tempState = currentState;
  148.                     currentState = PAUSE;
  149.                 }
  150.         break;
  151.  
  152.         case NIGHT:
  153.                 light_value = LS.getPercentValue();
  154.                 if(light_value>=50){
  155.                     currentState = OPEN;
  156.                 }
  157.                 if(SW.getSwitch(2)){
  158.                     currentState = IDLE;
  159.                 }
  160.                 if(SW.getSwitch(1)){
  161.                     currentState = MORNING;
  162.                 }
  163.                 if(SW.getSwitch(3)){
  164.                     tempState = currentState;
  165.                     currentState = PAUSE;
  166.                 }
  167.  
  168.  
  169.             break;
  170.  
  171.             }*////
  172.  
  173.  
  174.  
  175.  
  176.         }
  177.  
  178.     }
  179.     return 0;
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement