[资料]【HarmonyOS HiSpark Wi-Fi IoT 套件试用连载】之OLED

阅读量0
0
0
`使用WIFIIOT套件,直观交互最多的就是OLED。
源码LED_example.c里去.把所有的io_9改成11:
  1. /*
  2. * Copyright (c) 2020 Huawei Device Co., Ltd.
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. *     http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */

  15. #include <stdio.h>

  16. #include <unistd.h>

  17. #include "ohos_init.h"
  18. #include "cmsis_os2.h"
  19. #include "wifiiot_gpio.h"
  20. #include "wifiiot_gpio_ex.h"

  21. #define LED_INTERVAL_TIME_US 300000
  22. #define LED_TASK_STACK_SIZE 512
  23. #define LED_TASK_PRIO 25

  24. enum LedState
  25. {
  26.     LED_ON = 0,
  27.     LED_OFF,
  28.     LED_SPARK,
  29. };

  30. enum LedState g_ledState = LED_SPARK;

  31. static void *LedTask(const char *arg)
  32. {
  33.     (void)arg;
  34.     while (1)
  35.     {
  36.         switch (g_ledState)
  37.         {
  38.         case LED_ON:
  39.             GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_11, 1);
  40.             usleep(LED_INTERVAL_TIME_US);
  41.             break;
  42.         case LED_OFF:
  43.             GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_11, 0);
  44.             usleep(LED_INTERVAL_TIME_US);
  45.             break;
  46.         case LED_SPARK:
  47.             GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_11, 0);
  48.             usleep(LED_INTERVAL_TIME_US);
  49.             GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_11, 1);
  50.             usleep(LED_INTERVAL_TIME_US);
  51.             break;
  52.         default:
  53.             usleep(LED_INTERVAL_TIME_US);
  54.             break;
  55.         }
  56.     }

  57.     return NULL;
  58. }

  59. static void LedExampleEntry(void)
  60. {
  61.     osThreadAttr_t attr;
  62.     printf("LedExampleEntry
  63. ");
  64.     GpioInit();
  65.     IoSetFunc(WIFI_IOT_IO_NAME_GPIO_11, WIFI_IOT_IO_FUNC_GPIO_11_GPIO);
  66.     GpioSetDir(WIFI_IOT_IO_NAME_GPIO_11, WIFI_IOT_GPIO_DIR_OUT);

  67.     attr.name = "LedTask";
  68.     attr.attr_bits = 0U;
  69.     attr.cb_mem = NULL;
  70.     attr.cb_size = 0U;
  71.     attr.stack_mem = NULL;
  72.     attr.stack_size = LED_TASK_STACK_SIZE;
  73.     attr.priority = LED_TASK_PRIO;

  74.     if (osThreadNew((osThreadFunc_t)LedTask, NULL, &attr) == NULL)
  75.     {
  76.         printf("[LedExample] Falied to create LedTask!
  77. ");
  78.     }
  79. }

  80. SYS_RUN(LedExampleEntry);
复制代码





`
e57a633b692903bfae566b924e59498.png

回帖

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容图片侵权或者其他问题,请联系本站作侵删。 侵权投诉
链接复制成功,分享给好友