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

描述

本文来源电子发烧友社区,作者:张亭彪, 帖子地址:https://bbs.elecfans.com/jishu_2011342_1_1.html

使用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.  
  16. #include
  17.  
  18. #include
  19.  
  20. #include "ohos_init.h"
  21. #include "cmsis_os2.h"
  22. #include "wifiiot_gpio.h"
  23. #include "wifiiot_gpio_ex.h"
  24.  
  25. #define LED_INTERVAL_TIME_US 300000
  26. #define LED_TASK_STACK_SIZE 512
  27. #define LED_TASK_PRIO 25
  28.  
  29. enum LedState
  30. {
  31.     LED_ON = 0,
  32.     LED_OFF,
  33.     LED_SPARK,
  34. };
  35.  
  36. enum LedState g_ledState = LED_SPARK;
  37.  
  38. static void *LedTask(const char *arg)
  39. {
  40.     (void)arg;
  41.     while (1)
  42.     {
  43.         switch (g_ledState)
  44.         {
  45.         case LED_ON:
  46.             GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_11, 1);
  47.             usleep(LED_INTERVAL_TIME_US);
  48.             break;
  49.         case LED_OFF:
  50.             GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_11, 0);
  51.             usleep(LED_INTERVAL_TIME_US);
  52.             break;
  53.         case LED_SPARK:
  54.             GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_11, 0);
  55.             usleep(LED_INTERVAL_TIME_US);
  56.             GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_11, 1);
  57.             usleep(LED_INTERVAL_TIME_US);
  58.             break;
  59.         default:
  60.             usleep(LED_INTERVAL_TIME_US);
  61.             break;
  62.         }
  63.     }
  64.  
  65.     return NULL;
  66. }
  67.  
  68. static void LedExampleEntry(void)
  69. {
  70.     osThreadAttr_t attr;
  71.     printf("LedExampleEntry
  72. ");
  73.     GpioInit();
  74.     IoSetFunc(WIFI_IOT_IO_NAME_GPIO_11, WIFI_IOT_IO_FUNC_GPIO_11_GPIO);
  75.     GpioSetDir(WIFI_IOT_IO_NAME_GPIO_11, WIFI_IOT_GPIO_DIR_OUT);
  76.  
  77.     attr.name = "LedTask";
  78.     attr.attr_bits = 0U;
  79.     attr.cb_mem = NULL;
  80.     attr.cb_size = 0U;
  81.     attr.stack_mem = NULL;
  82.     attr.stack_size = LED_TASK_STACK_SIZE;
  83.     attr.priority = LED_TASK_PRIO;
  84.  
  85.     if (osThreadNew((osThreadFunc_t)LedTask, NULL, &attr) == NULL)
  86.     {
  87.         printf("[LedExample] Falied to create LedTask!
  88. ");
  89.     }
  90. }
  91.  
  92. SYS_RUN(LedExampleEntry);
复制代码



打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分