社区导航

 

搜索
查看: 502|回复: 2

[蓝牙BLE] BlueNRG-1控制8颗WS2812B实现摇摇棒显示EEWORLD

[复制链接]

5706

TA的帖子

9

TA的资源

版主

Rank: 6Rank: 6

发表于 2018-12-25 15:32 | 显示全部楼层 |阅读模式

先把点阵显示实现了
手机拍下来的效果不好
实际色彩比这个酷多了
8%IRJPE2{VI@Q5%(VCWB0SM.png
主要代码

  1. #include "display.h"
  2. #include "spi.h"
  3. #include "ws2812b.h"
  4. #include <stdio.h>
  5. #include <string.h>

  6. #define BACKGROUND_COLOR  0x000000
  7. #define FOREGROUND_COLOR  0x0F2F30
  8. #define BIT_TO_COLOR(byte,bit_index) (((byte & 1ul<<bit_index) == 1ul<<bit_index)?FOREGROUND_COLOR:BACKGROUND_COLOR)
  9. #define GET_BIT_OF_BYTE(byte,bit_index) (((byte & 1ul<<bit_index) == 1ul<<bit_index)?1:0)

  10. #define WS2812B_COUNT 8
  11. uint32_t color_buffer[WS2812B_COUNT];
  12. //RGB颜色缓冲转换为WS2812支持的SPI数据缓冲,一个RGB(24位)对应9个字节,WS2812B的一位需要3位,即110=1,100=0
  13. uint8_t ws2812b_buffer[WS2812B_COUNT * 9];



  14. //跑马灯那颗灯珠的位置
  15. uint16_t index = 0;

  16. //从上向下扫描
  17. uint8_t table_of_digits[40][8]=
  18. {
  19.     {0x1C,0x22,0x22,0x22,0x22,0x22,0x22,0x1C},//0
  20.     {0x08,0x18,0x08,0x08,0x08,0x08,0x08,0x1C},//1
  21.     {0x1C,0x22,0x02,0x02,0x1C,0x20,0x20,0x3E},//2
  22.     {0x1C,0x22,0x02,0x1C,0x02,0x02,0x22,0x1C},//3
  23.     {0x08,0x18,0x28,0x48,0x7C,0x08,0x08,0x08},//4
  24.     {0x3E,0x20,0x20,0x3E,0x02,0x02,0x22,0x1C},//5
  25.     {0x1C,0x22,0x20,0x3C,0x22,0x22,0x22,0x1C},//6
  26.     {0x3E,0x02,0x04,0x08,0x10,0x10,0x10,0x10},//7
  27.     {0x1C,0x22,0x22,0x1C,0x22,0x22,0x22,0x1C},//8
  28.     {0x1C,0x22,0x22,0x22,0x1E,0x02,0x22,0x1C},//9
  29.     {0x00,0x1C,0x22,0x22,0x22,0x3E,0x22,0x22},//A
  30.     {0x00,0x3C,0x22,0x22,0x3E,0x22,0x22,0x3C},//B
  31.     {0x00,0x1C,0x22,0x20,0x20,0x20,0x22,0x1C},//C
  32.     {0x00,0x3C,0x22,0x22,0x22,0x22,0x22,0x3C},//D
  33.     {0x00,0x3E,0x20,0x20,0x3E,0x20,0x20,0x3E},//E
  34.     {0x00,0x3E,0x20,0x20,0x3E,0x20,0x20,0x20},//F
  35.     {0x00,0x1C,0x22,0x20,0x3E,0x22,0x22,0x1C},//G
  36.     {0x00,0x22,0x22,0x22,0x3E,0x22,0x22,0x22},//H
  37.     {0x00,0x1C,0x08,0x08,0x08,0x08,0x08,0x1C},//I
  38.     {0x00,0x3E,0x08,0x08,0x08,0x08,0x28,0x18},//J
  39.     {0x00,0x20,0x2C,0x30,0x20,0x30,0x2C,0x20},//K
  40.     {0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x3E},//L
  41.     {0x00,0x42,0x66,0x5A,0x42,0x42,0x42,0x42},//M
  42.     {0x00,0x00,0x2C,0x32,0x22,0x22,0x22,0x22},//n
  43.     {0x00,0x1C,0x22,0x22,0x22,0x22,0x22,0x1C},//O
  44.     {0x00,0x3C,0x22,0x22,0x3C,0x20,0x20,0x20},//P
  45.     {0x00,0x1C,0x22,0x22,0x22,0x2A,0x26,0x1F},//Q
  46.     {0x00,0x38,0x24,0x24,0x38,0x30,0x28,0x24},//R
  47.     {0x00,0x1C,0x22,0x20,0x1C,0x02,0x22,0x1C},//S
  48.     {0x00,0x3E,0x08,0x08,0x08,0x08,0x08,0x08},//T
  49.     {0x00,0x42,0x42,0x42,0x42,0x42,0x42,0x3C},//U
  50.     {0x00,0x22,0x22,0x22,0x14,0x14,0x08,0x00},//V
  51.     {0x00,0x41,0x41,0x49,0x55,0x55,0x63,0x41},//W
  52.     {0x00,0x00,0x42,0x24,0x18,0x18,0x24,0x42},//X
  53.     {0x00,0x22,0x22,0x14,0x08,0x10,0x20,0x00},//Y
  54.     {0x00,0x3E,0x02,0x04,0x08,0x10,0x20,0x3E},//Z
  55. };
  56. //获取一个字符的点阵,按行扫描,一搬从上至下
  57. uint8_t get_digit_row(char c,uint8_t row_index)
  58. {
  59.   uint8_t char_index;
  60.   char_index = (c>='A') ? c-'A'+10 :c-'0';
  61.   return table_of_digits[char_index][row_index];
  62. }
  63. //获取一个字符的点阵,按列扫描,一搬从上至下读点,从左至右读列
  64. uint8_t get_digit_column(char c,uint8_t column_index)
  65. {
  66.   uint8_t i;
  67.   uint8_t char_index;
  68.   char_index = (c>='A') ? c-'A'+10 :c-'0';
  69.   uint8_t column_code = 0;
  70.   //将行扫转成列扫
  71.   for(i=0;i<8;i++)
  72.   {
  73.     column_code <<= 1;
  74.     column_code |= GET_BIT_OF_BYTE(table_of_digits[char_index][i],7 - column_index);
  75.   }  
  76.   return column_code;
  77. }

  78. void delay1(uint32_t d)
  79. {
  80.   uint32_t i,j;
  81.   for(i=0;i<d;i++)
  82.   {
  83.     for(j=0;j<100;j++);
  84.   }
  85. }
  86. void ws2812b_string_display(char * str)
  87. {
  88.   uint16_t i,j,k;
  89.   uint16_t strcount;
  90.   strcount = strlen(str);
  91.   uint8_t y_code;
  92.   uint32_t colors[8];
  93.   int32_t light_count = 8;
  94.   //字符数量
  95.   for(i=0;i<strcount;i++)
  96.   {
  97.     //单字符列数据
  98.     for(j=0;j<8;j++)
  99.     {
  100.       y_code = get_digit_column(str[i],j);
  101.       //单列点数量
  102.       for(k=0;k<8;k++)
  103.       {
  104.           colors[k] = BIT_TO_COLOR(y_code,7-k);
  105.       }
  106.       //填充完一列8个点后显示      
  107.       IntColorsToWS2812BBytes(ws2812b_buffer,colors,light_count);
  108.       DMASpi_Sending((uint32_t)ws2812b_buffer,light_count * 9);
  109.       delay1(10);
  110.     }
  111.   }
  112.   
  113. }
复制代码




工程文件
游客,如果您要查看本帖隐藏内容请回复

虾扯蛋


回复

使用道具 举报

845

TA的帖子

1

TA的资源

一粒金砂(高级)

Rank: 3Rank: 3

发表于 2018-12-25 15:45 | 显示全部楼层
太忙了,想玩没空玩


回复

使用道具 举报

10

TA的帖子

0

TA的资源

一粒金砂(中级)

Rank: 2

发表于 前天 11:05 | 显示全部楼层
学习下


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

  • 论坛活动 E手掌握

    扫码关注
    EEWORLD 官方微信

  • EE福利  唾手可得

    扫码关注
    EE福利 唾手可得

Archiver|手机版|小黑屋|电子工程世界 ( 京ICP证 060456 )

GMT+8, 2019-3-25 09:08 , Processed in 0.119483 second(s), 17 queries , Gzip On, MemCache On.

快速回复 返回顶部 返回列表