Advertisement
whitesurge

Project CMPE 30

Dec 1st, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.24 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. typedef enum{IDLE, MORNING} State;
  8.  
  9. int main(void){
  10.  
  11.     State currentState = IDLE;
  12.     int light_value = LS.getPercentValue();
  13.     GPIO pin20(P1_20);
  14.     pin20.setAsOutput();
  15.     pin20.setLow();
  16.     int temp1 = 1;
  17.  
  18.     while(1){
  19.  
  20.  
  21.         //LD.setNumber(light_value);
  22.         delay_ms(100);
  23.  
  24.         switch(currentState){
  25.  
  26.             case IDLE:
  27.                 while(temp1){
  28.  
  29.  
  30.                     printf("IDLE\n");
  31.                     printf("IDLE\n");
  32.                     if(SW.getSwitch(1)){
  33.                         currentState = MORNING;
  34.                         printf("After Declaring State");
  35.                         temp1=0;
  36.                         //break;
  37.  
  38.                     }
  39.                 }
  40.                 printf("Break2");
  41.                 delay_ms(100);
  42.                 printf("Delay3");
  43.                 currentState = MORNING;
  44.                 printf("Delay4");
  45.                 delay_ms(100);
  46.                 printf("Delay5");
  47.                 break;
  48.  
  49.  
  50.             case MORNING:
  51.                 printf("Morning0\n");
  52.                 while(1){
  53.                     //printf("Morning\n");
  54.  
  55.  
  56.                     light_value = LS.getPercentValue();
  57.                     if(light_value<4096){
  58.                         //printf("SETHIGH");
  59.                         pin20.setHigh();
  60.                     }else{
  61.                         printf("SETLOW");
  62.                         pin20.setLow();
  63.                     }
  64.                 }
  65.  
  66.  
  67.                 if(SW.getSwitch(1)){
  68.                     currentState = IDLE;
  69.                 }
  70.  
  71.                 break;
  72.  
  73.  
  74.  
  75.  
  76.  
  77.                 /***
  78.                  *
  79.                  *
  80.  
  81.  
  82.             pin20.setHigh();
  83.             pin20.setLow();
  84.  
  85.             delay_ms(200);
  86.             // Switch #1
  87.             if(SW.getSwitch(1)) {
  88.                 LE.on(1);
  89.             }
  90.             else {
  91.                 LE.off(1);
  92.             }
  93.  
  94.             //Switch #2
  95.  
  96.             if(SW.getSwitch(2)){
  97.                 int light_value = LS.getPercentValue();
  98.                 LD.setNumber(light_value);
  99.             }*////
  100.  
  101.  
  102.  
  103.  
  104.         }
  105.         return 0;
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement