Guest User

Azure Sphere Test

a guest
Jul 31st, 2019
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.97 KB | None | 0 0
  1. #include <stdbool.h>
  2. #include <errno.h>
  3. #include <string.h>
  4. #include <time.h>
  5.  
  6. #include <applibs/log.h>
  7. #include <applibs/gpio.h>
  8.  
  9. int main(void)
  10. {
  11.     // This minimal Azure Sphere app repeatedly toggles GPIO 9, which is the green channel of RGB
  12.     // LED 1 on the MT3620 RDB.
  13.     // Use this app to test that device and SDK installation succeeded that you can build,
  14.     // deploy, and debug an app with Visual Studio, and that you can deploy an app over the air,
  15.     // per the instructions here: https://docs.microsoft.com/azure-sphere/quickstarts/qs-overview
  16.     //
  17.     // It is NOT recommended to use this as a starting point for developing apps; instead use
  18.     // the extensible samples here: https://github.com/Azure/azure-sphere-samples
  19.     Log_Debug(
  20.         "\nVisit https://github.com/Azure/azure-sphere-samples for extensible samples to use as a "
  21.         "starting point for full applications.\n");
  22.  
  23.     int fd = GPIO_OpenAsOutput(9, GPIO_OutputMode_PushPull, GPIO_Value_High);
  24.     if (fd < 0) {
  25.         Log_Debug(
  26.             "Error opening GPIO: %s (%d). Check that app_manifest.json includes the GPIO used.\n",
  27.             strerror(errno), errno);
  28.         return -1;
  29.     }
  30.     int fd2 = GPIO_OpenAsOutput(10, GPIO_OutputMode_PushPull, GPIO_Value_High);
  31.     if (fd2 < 0) {
  32.         Log_Debug(
  33.             "Error opening GPIO: %s (%d). Check that app_manifest.json includes the GPIO used.\n",
  34.             strerror(errno), errno);
  35.         return -1;
  36.     }
  37.     int fd3 = GPIO_OpenAsOutput(8, GPIO_OutputMode_PushPull, GPIO_Value_High);
  38.     if (fd3 < 0) {
  39.         Log_Debug(
  40.             "Error opening GPIO: %s (%d). Check that app_manifest.json includes the GPIO used.\n",
  41.             strerror(errno), errno);
  42.         return -1;
  43.     }
  44.     /*
  45.     static int buttFd = -1;
  46.     GPIO_Value_Type newButtonState;
  47.     GPIO_Id GPIO12;
  48.     buttFd = GPIO_OpenAsInput(27);
  49.     */
  50.     const struct timespec sleepTime = {1, 0};
  51.  
  52.     typedef enum State {ONE=1,TWO,THREE,FOUR,FIVE,SIX} State;
  53.  
  54.     State Machine = ONE;
  55.     while (true) {
  56.        
  57.         //int result = GPIO_GetValue(buttFd, &newButtonState);
  58.         //nanosleep(&sleepTime, NULL);
  59.         int res;
  60.        
  61.         switch (Machine)
  62.         {
  63.         case ONE:
  64.             GPIO_SetValue(fd, GPIO_Value_High);
  65.             nanosleep(&sleepTime, NULL);   
  66.             Log_Debug("LED 1 switched ON\n");
  67.                 Machine = TWO;
  68.             break;
  69.         case TWO:
  70.             GPIO_SetValue(fd, GPIO_Value_Low);
  71.             nanosleep(&sleepTime, NULL);
  72.             Log_Debug("LED 1 switched OFF\n");
  73.             Machine = THREE;
  74.             break;
  75.         case THREE:
  76.             GPIO_SetValue(fd2, GPIO_Value_High);
  77.             Log_Debug("LED 2 switched ON\n");
  78.             Machine = FOUR;
  79.             break;
  80.         case FOUR:
  81.             GPIO_SetValue(fd2, GPIO_Value_Low);
  82.             nanosleep(&sleepTime, NULL);
  83.             Log_Debug("LED 2 switched OFF\n");
  84.             Machine = FIVE;
  85.             break;
  86.         case FIVE:
  87.             GPIO_SetValue(fd3, GPIO_Value_High);
  88.             nanosleep(&sleepTime, NULL);
  89.             Log_Debug("LED 3 switched ON\n");
  90.             Machine = SIX;
  91.         case SIX:
  92.             GPIO_SetValue(fd3, GPIO_Value_Low);
  93.             nanosleep(&sleepTime, NULL);
  94.             Log_Debug("LED 3 switched OFF\n");
  95.             Machine = ONE;
  96.         }    
  97.    
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment