Embedded World 2021 - Infineon ModusToolbox PSoC 6 Drone 

 

Summary

In lesson 7 we will finish this Frankenstein drone setup by adding WS2812 Strip LEDs.  At the end of lesson one you will have the “WS2812 LED” block colored green.  Here is the architecture:

Learning Objectives

  1. Have fun by adding another cool library – WS2812

Procedure

  1. Create a new project
  2. Add the IoT Expert WS2812 Library
  3. Modify motor_task.c
  4. Test

1. Create a new project

Start from the CY8CKIT-062S2-43012

Give the project a sensible name.  In this case IoT_Expert_Embedded_World_2021_Lesson7

2. Add the IoT Expert WS2812 Library

You need to find the IoT Expert WS2812 library and include it into your project.

3. Modify motor_task.c

Include the header file for the library.

#include "ws2812.h"

The number of LEDs in our system

#define		NUM_LEDS				(61)

Define some colors to use and initialize the LED strip

/* LED color array - 7 different colors each with RGB values */
uint8_t ledColors[7][3] = {
        { 0,  0,  0},	// Off
        {20,  0, 30},	// Violet
        { 0,  0, 50},	// Blue
        { 0, 50,  0},	// Green
        {30, 20,  0},	// Yellow
        {42,  8,  0},	// Orange
        {50,  0,  0},	// Red
};

 uint8_t ledColorRow = 0;
 uint8_t ledColorRowPrev = 0;
/* Initialize LED strips */
ws2812_init(NUM_LEDS, P10_0, P10_1, P10_2);

A bit of code to send updates to the LED strip based on the status of the motor.

/* Calculate LED color and update if it has changed */
            if(motorState == false)
            {
                /* Turn off LEDs */
                ws2812_setMultiRGB(0, NUM_LEDS-1, 0, 0, 0);
                ws2812_update();
                ledColorRowPrev = 0;
            }
            else
            {
                ledColorRow = 1 + (uint8_t)((( (uint16_t)motorSpeed - (uint16_t)RPM_MIN ) * 5) / ((uint16_t)RPM_MAX - (uint16_t)RPM_MIN)); /* Determine row to use */
                if(ledColorRowPrev != ledColorRow)
                {
                    ws2812_setMultiRGB(0, NUM_LEDS-1, ledColors[ledColorRow][0], ledColors[ledColorRow][1], ledColors[ledColorRow][2]);
                    ws2812_update();
                    ledColorRowPrev = ledColorRow;
                }
            }

4. Test

Let it rip tater chip

Here it is with the LED strips on…

Resources for Project

You can find the completed project in your project creator dialog by filtering for “IoT Expert Embedded”.  This is lesson 7

You can also clone this project at git@github.com:iotexpert/ew21-lesson2.git or https://github.com/iotexpert/ew21-lesson2

Recommended Posts

No comment yet, add your voice below!


Add a Comment

Your email address will not be published. Required fields are marked *