Advertisement
whitesurge

Updated Prject

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