Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: lcd neoPixelRing12 view2 BSP_DISCO_F746NG view1 button
NeoPixelRing12/NeoPixelRing12.cpp
- Committer:
- Rhamao
- Date:
- 2020-06-04
- Revision:
- 7:1887c4e4b5de
File content as of revision 7:1887c4e4b5de:
#include "NeoPixelRing12.h"
#include "mbed.h"
#include "string.h"
NeoPixelRing12::NeoPixelRing12(DigitalOut _digitalOutPin):digitalOutPin(_digitalOutPin)
{
}
bool NeoPixelRing12::rst( )
{
digitalOutPin=0;
wait_us(RST_TIME_IN_US);
return true;
}
bool NeoPixelRing12::rgbToDataStructure(char* rgbCode){
uint8_t i = 0;
uint8_t offset = 0;
//Red
for (i=0; i<6; i++) {
if(i==0)
offset=11;
if(i==1)
offset=15;
if(i==2)
offset=3;
if(i==3)
offset=7;
if(i==4)
offset=19;
if(i==5)
offset=23;
switch (rgbCode[i]) {
case '0':
//////////cout << "0000";
rgbDataStructure[offset]=false;
rgbDataStructure[offset-1]=false;
rgbDataStructure[offset-2]=false;
rgbDataStructure[offset-3]=false;
break;
case '1':
////////////////////cout << "0001";
rgbDataStructure[offset]=true;
rgbDataStructure[offset-1]=false;
rgbDataStructure[offset-2]=false;
rgbDataStructure[offset-3]=false;
break;
case '2':
////////cout << "0010";
rgbDataStructure[offset]=false;
rgbDataStructure[offset-1]=true;
rgbDataStructure[offset-2]=false;
rgbDataStructure[offset-3]=false;
break;
case '3':
////////cout << "0011";
rgbDataStructure[offset]=true;
rgbDataStructure[offset-1]=true;
rgbDataStructure[offset-2]=false;
rgbDataStructure[offset-3]=false;
break;
case '4':
////////cout << "0100";
rgbDataStructure[offset]=false;
rgbDataStructure[offset-1]=false;
rgbDataStructure[offset-2]=true;
rgbDataStructure[offset-3]=false;
break;
case '5':
////////cout << "0101";
rgbDataStructure[offset]=true;
rgbDataStructure[offset-1]=false;
rgbDataStructure[offset-2]=true;
rgbDataStructure[offset-3]=false;
break;
case '6':
////////cout << "0110";
rgbDataStructure[offset]=false;
rgbDataStructure[offset-1]=true;
rgbDataStructure[offset-2]=true;
rgbDataStructure[offset-3]=false;
break;
case '7':
////////cout << "0111";
rgbDataStructure[offset]=true;
rgbDataStructure[offset-1]=true;
rgbDataStructure[offset-2]=true;
rgbDataStructure[offset-3]=false;
break;
case '8':
////////cout << "1000";
rgbDataStructure[offset]=false;
rgbDataStructure[offset-1]=false;
rgbDataStructure[offset-2]=false;
rgbDataStructure[offset-3]=true;
break;
case '9':
////////cout << "1001";
rgbDataStructure[offset]=true;
rgbDataStructure[offset-1]=false;
rgbDataStructure[offset-2]=false;
rgbDataStructure[offset-3]=true;
break;
case 'A':
case 'a':
////////cout << "1010";
rgbDataStructure[offset]=false;
rgbDataStructure[offset-1]=true;
rgbDataStructure[offset-2]=false;
rgbDataStructure[offset-3]=true;
break;
case 'B':
case 'b':
////////cout << "1011";
rgbDataStructure[offset]=true;
rgbDataStructure[offset-1]=true;
rgbDataStructure[offset-2]=false;
rgbDataStructure[offset-3]=true;
break;
case 'C':
case 'c':
////////cout << "1100";
rgbDataStructure[offset]=false;
rgbDataStructure[offset-1]=false;
rgbDataStructure[offset-2]=true;
rgbDataStructure[offset-3]=true;
break;
case 'D':
case 'd':
////////cout << "1101";
rgbDataStructure[offset]=true;
rgbDataStructure[offset-1]=false;
rgbDataStructure[offset-2]=true;
rgbDataStructure[offset-3]=true;
break;
case 'E':
case 'e':
////////cout << "1110";
rgbDataStructure[offset]=false;
rgbDataStructure[offset-1]=true;
rgbDataStructure[offset-2]=true;
rgbDataStructure[offset-3]=true;
break;
case 'F':
case 'f':
////////cout << "1111";
rgbDataStructure[offset]=true;
rgbDataStructure[offset-1]=true;
rgbDataStructure[offset-2]=true;
rgbDataStructure[offset-3]=true;
break;
default:
return false;
}
}
return true;
}
bool NeoPixelRing12::bit(bool value){
if(!value){
digitalOutPin = 1;
wait_ns(190);
digitalOutPin = 0;
wait_ns(740);
}
else{
digitalOutPin = 1;
wait_ns(600);
digitalOutPin = 0;
wait_ns(600);
}
return true;
}
bool NeoPixelRing12::setLights(int nbOfLeds, char* rgbCode){
rgbToDataStructure(rgbCode);
for(int i=0; i<nbOfLeds; i++){
for(int y=0; y<24; y++){
bit(rgbDataStructure[y]);
}
}
return true;
}