Skip to content

Commit

Permalink
Improved example to show using max strength
Browse files Browse the repository at this point in the history
  • Loading branch information
naylom committed Sep 2, 2023
1 parent a1d55d7 commit 9e991d2
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 32 deletions.
3 changes: 2 additions & 1 deletion .vscode/arduino.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"board": "arduino:samd:mkrwifi1010",
"sketch": "examples\\BasicTest\\BasicTest.ino"
"sketch": "examples\\BasicTest\\BasicTest.ino",
"port": "COM6"
}
36 changes: 18 additions & 18 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"configurations": [
{
"name": "Arduino",
"compilerPath": "C:\\Users\\mark_\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\\7-2017q4\\bin\\arm-none-eabi-g++",
"compilerPath": "C:\\Users\\Mark Naylor\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\\7-2017q4\\bin\\arm-none-eabi-g++",
"compilerArgs": [
"-mcpu=cortex-m0plus",
"-mthumb",
Expand All @@ -19,25 +19,25 @@
],
"intelliSenseMode": "gcc-x64",
"includePath": [
"C:\\Users\\mark_\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\CMSIS\\4.5.0\\CMSIS\\Include\\",
"C:\\Users\\mark_\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\CMSIS-Atmel\\1.2.0\\CMSIS\\Device\\ATMEL\\",
"C:\\Users\\mark_\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\samd\\1.8.13\\cores\\arduino\\api\\deprecated",
"C:\\Users\\mark_\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\samd\\1.8.13\\cores\\arduino\\api\\deprecated-avr-comp",
"C:\\Users\\mark_\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\samd\\1.8.13\\cores\\arduino",
"C:\\Users\\mark_\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\samd\\1.8.13\\variants\\mkrwifi1010",
"F:\\mark_\\OneDrive\\Documents\\Arduino\\libraries\\MNMkrWiFi1010RGBLEDLib\\src",
"F:\\mark_\\OneDrive\\Documents\\Arduino\\libraries\\WiFiNINA\\src",
"F:\\mark_\\OneDrive\\Documents\\Arduino\\libraries\\MNTimerLib\\src",
"C:\\Users\\mark_\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\samd\\1.8.13\\libraries\\SPI",
"c:\\users\\mark_\\appdata\\local\\arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\\7-2017q4\\arm-none-eabi\\include\\c++\\7.2.1",
"c:\\users\\mark_\\appdata\\local\\arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\\7-2017q4\\arm-none-eabi\\include\\c++\\7.2.1\\arm-none-eabi",
"c:\\users\\mark_\\appdata\\local\\arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\\7-2017q4\\arm-none-eabi\\include\\c++\\7.2.1\\backward",
"c:\\users\\mark_\\appdata\\local\\arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\\7-2017q4\\lib\\gcc\\arm-none-eabi\\7.2.1\\include",
"c:\\users\\mark_\\appdata\\local\\arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\\7-2017q4\\lib\\gcc\\arm-none-eabi\\7.2.1\\include-fixed",
"c:\\users\\mark_\\appdata\\local\\arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\\7-2017q4\\arm-none-eabi\\include"
"C:\\Users\\Mark Naylor\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\CMSIS\\4.5.0\\CMSIS\\Include\\",
"C:\\Users\\Mark Naylor\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\CMSIS-Atmel\\1.2.0\\CMSIS\\Device\\ATMEL\\",
"C:\\Users\\Mark Naylor\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\samd\\1.8.13\\cores\\arduino\\api\\deprecated",
"C:\\Users\\Mark Naylor\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\samd\\1.8.13\\cores\\arduino\\api\\deprecated-avr-comp",
"C:\\Users\\Mark Naylor\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\samd\\1.8.13\\cores\\arduino",
"C:\\Users\\Mark Naylor\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\samd\\1.8.13\\variants\\mkrwifi1010",
"F:\\Users\\Mark Naylor\\OneDrive\\Documents\\Arduino\\libraries\\MNMkrWiFi1010RGBLEDLib-1.0.5\\src",
"F:\\Users\\Mark Naylor\\OneDrive\\Documents\\Arduino\\libraries\\WiFiNINA\\src",
"F:\\Users\\Mark Naylor\\OneDrive\\Documents\\Arduino\\libraries\\MNTimerLib\\src",
"C:\\Users\\Mark Naylor\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\samd\\1.8.13\\libraries\\SPI",
"c:\\users\\mark naylor\\appdata\\local\\arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\\7-2017q4\\arm-none-eabi\\include\\c++\\7.2.1",
"c:\\users\\mark naylor\\appdata\\local\\arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\\7-2017q4\\arm-none-eabi\\include\\c++\\7.2.1\\arm-none-eabi",
"c:\\users\\mark naylor\\appdata\\local\\arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\\7-2017q4\\arm-none-eabi\\include\\c++\\7.2.1\\backward",
"c:\\users\\mark naylor\\appdata\\local\\arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\\7-2017q4\\lib\\gcc\\arm-none-eabi\\7.2.1\\include",
"c:\\users\\mark naylor\\appdata\\local\\arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\\7-2017q4\\lib\\gcc\\arm-none-eabi\\7.2.1\\include-fixed",
"c:\\users\\mark naylor\\appdata\\local\\arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\\7-2017q4\\arm-none-eabi\\include"
],
"forcedInclude": [
"C:\\Users\\mark_\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\samd\\1.8.13\\cores\\arduino\\Arduino.h"
"C:\\Users\\Mark Naylor\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\samd\\1.8.13\\cores\\arduino\\Arduino.h"
],
"cStandard": "c11",
"cppStandard": "c++11",
Expand Down
20 changes: 13 additions & 7 deletions examples/BasicTest/BasicTest.ino
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
//#define MKR_RGB_INVERT
#define MKR_RGB_INVERT
#include <MNRGBLEDBaseLib.h>
/*
Example for library showing how to use built in Mkr Wifi 1010 RGB LED and an external LED
NB Some MKR wifi boards have red and green pins on built in LED inverted. There appears no way to detect this in code. If you find that the red and green colours are inverted
then uncomment the first line with the #define. The library will then compensate. Note the #define must occur before the #include
then call the Invert() function in the setup. The library will then compensate.
*/
constexpr auto FLASHTIME = 10; // every 2 seconds, ie 1 = 1/5 second
const int iRedPin = A4;
const int iGreenPin = A5;
const int iBluePin = A6;
const int iRedPin = 6; // Should be pwm pins it you want 24 bit colour
const int iGreenPin = 7;
const int iBluePin = 8;

// create instance
CRGBLED myLED ( iRedPin, iGreenPin, iBluePin );
// create instance of external rgb led
// such leds often have different strengths of brightness between the three colours. The size of the reisstir used for each led can compensate. If however this is not enough the library allows a max strength value to be set for each colour.
// This is then used to scale any SETLEDColour colours. By default the max value for a red green or blue colour is 255. If the respective max strength is set to say 200 then any request to set the colour from 0 to 255 will be scaled to 0 to 200,
// ie 255 will actually generate 200 and 66 generate 66 * 200 / 255. If no max strengths are set there is no scaling and the full range is used.

CRGBLED myLED ( iRedPin, iGreenPin, iBluePin, 255, 127, 64 ); // sets max red to 255, max green to 127 and max blue to 64

void setup()
{
// Optionally switch red and green signals for those MKR boards that need it.
TheMKR_RGB_LED.Invert();
}

void loop()
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=MNRGBLEDBaseLib
version=1.0.4
version=1.0.5
author=Mark Naylor <mark_naylor@hotmail.com>
maintainer=Mark Naylor <mark_naylor@hotmail.com>
sentence= Base library to control RGB LED
Expand Down
11 changes: 9 additions & 2 deletions src/MNRGBLEDBaseLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ void CRGBLED::SetDeviceBlue ( uint8_t strength )
}

/* If we are compiling on MKR WiFI 1010 with built in RGB LED the create derived class to control in and declare an instance as there is only one such LED */

#ifdef ARDUINO_ARCH_SAMD
/*
#ifdef MKR_RGB_INVERT
const static int m_iMkrRedPin = 25;
const static int m_iMkrGreenPin = 26;
Expand All @@ -86,14 +88,20 @@ const static int m_iMkrRedPin = 26;
const static int m_iMkrGreenPin = 25;
const static int m_iMkrBluePin = 27;
#endif

*/
void CMkrWiFi1010RGBLED::InitDevice ()
{
WiFiDrv::pinMode ( m_iMkrRedPin, OUTPUT );
WiFiDrv::pinMode ( m_iMkrGreenPin, OUTPUT );
WiFiDrv::pinMode ( m_iMkrBluePin, OUTPUT );
}

void CMkrWiFi1010RGBLED::Invert ()
{
m_iMkrRedPin = 25;
m_iMkrGreenPin = 26;
}

void CMkrWiFi1010RGBLED::SetDeviceRed ( uint8_t strength )
{
WiFiDrv::analogWrite ( m_iMkrRedPin, strength );
Expand All @@ -108,6 +116,5 @@ void CMkrWiFi1010RGBLED::SetDeviceBlue ( uint8_t strength )
{
WiFiDrv::analogWrite ( m_iMkrBluePin, strength );
}

CMkrWiFi1010RGBLED TheMKR_RGB_LED;
#endif
15 changes: 12 additions & 3 deletions src/MNRGBLEDBaseLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ class CRGBLED : public MNRGBLEDBaseLib
using MNRGBLEDBaseLib::MNRGBLEDBaseLib;

private:
int m_iRedPin;
int m_iGreenPin;
int m_iBluePin;
const int m_iRedPin;
const int m_iGreenPin;
const int m_iBluePin;

public:
CRGBLED ( const int iRedPin, const int iGreenPin, const int iBluePin, uint8_t maxRed = 255, uint8_t maxGreen = 255, uint8_t maxBlue = 255 ) : MNRGBLEDBaseLib ( maxRed, maxGreen, maxBlue ), m_iRedPin (iRedPin), m_iGreenPin ( iGreenPin ), m_iBluePin ( iBluePin ) {};
Expand All @@ -82,12 +82,21 @@ class CMkrWiFi1010RGBLED : public MNRGBLEDBaseLib
public:
using MNRGBLEDBaseLib::MNRGBLEDBaseLib;

private:
int m_iMkrRedPin = 26;
int m_iMkrGreenPin = 25;
int m_iMkrBluePin = 27;

public:
CMkrWiFi1010RGBLED (){};
void InitDevice ();
void Invert();
void SetDeviceRed ( uint8_t strength );
void SetDeviceGreen ( uint8_t strength );
void SetDeviceBlue ( uint8_t strength );
};


extern CMkrWiFi1010RGBLED TheMKR_RGB_LED;

#endif

0 comments on commit 9e991d2

Please sign in to comment.