Advertisement
whitesurge

Not Working

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