Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdbool.h>
- #include <errno.h>
- #include <string.h>
- #include <time.h>
- #include <applibs/log.h>
- #include <applibs/gpio.h>
- int main(void)
- {
- // This minimal Azure Sphere app repeatedly toggles GPIO 9, which is the green channel of RGB
- // LED 1 on the MT3620 RDB.
- // Use this app to test that device and SDK installation succeeded that you can build,
- // deploy, and debug an app with Visual Studio, and that you can deploy an app over the air,
- // per the instructions here: https://docs.microsoft.com/azure-sphere/quickstarts/qs-overview
- //
- // It is NOT recommended to use this as a starting point for developing apps; instead use
- // the extensible samples here: https://github.com/Azure/azure-sphere-samples
- Log_Debug(
- "\nVisit https://github.com/Azure/azure-sphere-samples for extensible samples to use as a "
- "starting point for full applications.\n");
- int fd = GPIO_OpenAsOutput(9, GPIO_OutputMode_PushPull, GPIO_Value_High);
- if (fd < 0) {
- Log_Debug(
- "Error opening GPIO: %s (%d). Check that app_manifest.json includes the GPIO used.\n",
- strerror(errno), errno);
- return -1;
- }
- int fd2 = GPIO_OpenAsOutput(10, GPIO_OutputMode_PushPull, GPIO_Value_High);
- if (fd2 < 0) {
- Log_Debug(
- "Error opening GPIO: %s (%d). Check that app_manifest.json includes the GPIO used.\n",
- strerror(errno), errno);
- return -1;
- }
- int fd3 = GPIO_OpenAsOutput(8, GPIO_OutputMode_PushPull, GPIO_Value_High);
- if (fd3 < 0) {
- Log_Debug(
- "Error opening GPIO: %s (%d). Check that app_manifest.json includes the GPIO used.\n",
- strerror(errno), errno);
- return -1;
- }
- /*
- static int buttFd = -1;
- GPIO_Value_Type newButtonState;
- GPIO_Id GPIO12;
- buttFd = GPIO_OpenAsInput(27);
- */
- const struct timespec sleepTime = {1, 0};
- typedef enum State {ONE=1,TWO,THREE,FOUR,FIVE,SIX} State;
- State Machine = ONE;
- while (true) {
- //int result = GPIO_GetValue(buttFd, &newButtonState);
- //nanosleep(&sleepTime, NULL);
- int res;
- switch (Machine)
- {
- case ONE:
- GPIO_SetValue(fd, GPIO_Value_High);
- nanosleep(&sleepTime, NULL);
- Log_Debug("LED 1 switched ON\n");
- Machine = TWO;
- break;
- case TWO:
- GPIO_SetValue(fd, GPIO_Value_Low);
- nanosleep(&sleepTime, NULL);
- Log_Debug("LED 1 switched OFF\n");
- Machine = THREE;
- break;
- case THREE:
- GPIO_SetValue(fd2, GPIO_Value_High);
- Log_Debug("LED 2 switched ON\n");
- Machine = FOUR;
- break;
- case FOUR:
- GPIO_SetValue(fd2, GPIO_Value_Low);
- nanosleep(&sleepTime, NULL);
- Log_Debug("LED 2 switched OFF\n");
- Machine = FIVE;
- break;
- case FIVE:
- GPIO_SetValue(fd3, GPIO_Value_High);
- nanosleep(&sleepTime, NULL);
- Log_Debug("LED 3 switched ON\n");
- Machine = SIX;
- case SIX:
- GPIO_SetValue(fd3, GPIO_Value_Low);
- nanosleep(&sleepTime, NULL);
- Log_Debug("LED 3 switched OFF\n");
- Machine = ONE;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment