Skip to content

Commit

Permalink
New added mode (1x RGB led)
Browse files Browse the repository at this point in the history
Second integration for Arduino to Blinkit project making it possible to receive notifications for Steem activities (upvotes, followers, posts) by blinking either 3 single colour led or 1 RGB led
  • Loading branch information
electronicsworld committed May 22, 2018
1 parent 59e0d38 commit 0c069a8
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 83 deletions.
297 changes: 214 additions & 83 deletions ArduinoBlinkitSketch.ino
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
char buffer[30];
char buffer[22];

int LED_ONE= 2; //pin for led 1
int LED_TWO= 3; //pin for led 2
int LED_THREE= 4; //pin for led 3
int RedPIN = 3; //pin for led 1 (single colour led) or pin for the Red led in the RGB led
int GreenPIN = 5; //pin for led 2 (single colour led) or pin for the Green led in the RGB led
int BluePIN = 6 ; //pin for led 3 (single colour led) or pin for the Blue led in the RGB led
//above pins must be DIGITAL PWM PINS (in Arduino Uno, PIN 3, 5, 6, 9, 10, 11 are PWM) in order to obtain the colours shades with the RGB led
int y=0;
int ledmode[2]; //this array will store the information regarding the ledmode (for now '1' for standard led mode but RGB mode will be coming soon and other modes also in the roadmap)
int blinkdelay[3]; //this array will store the information to be used for the blink speed for each led
int transferdata[3]; //array to be used to store the incoming settings and transfer them
int Nofblinks[3]; //this array will store the information to be used for the number of triggers to do (number of repeated triggers)
int transferdata[3]; //array to be used to store the incoming settings and transfer them to the right setting array
int ledmode[2]; //this array will store the information regarding the ledmode (mode 1 for 3x single colour leds and mode 2 for 1x RGB led )
int blinkdelay[3]; //this array will store the information to be used for the blink speed (in this case it is a delay between blinks)
int Nofblinks[3]; //this array will store the information to be used for the number of triggers/blinks to do (number of repeated triggers)
int BRIGHTU[3]; // This array will store the information regarding the brightness of the RGB led for the upvote trigger (3 values, 1 for for each colour to create the blend with the others)
int BRIGHTF[3];// This array will store the information regarding the brightness of the RGB led for the follower trigger (3 values, 1 for for each colour to create the blend with the others)
int BRIGHTP[3]; // This array will store the information regarding the brightness of the RGB led for the post trigger (3 values, 1 for for each colour to create the blend with the others)

void setup()
{
Serial.begin(14400);
Serial.begin(9600);
Serial.flush();
pinMode(LED_ONE, OUTPUT); //set the selected pins as output
pinMode(LED_TWO, OUTPUT);
pinMode(LED_THREE, OUTPUT);
pinMode(RedPIN, OUTPUT); //set the selected pins as output
pinMode(GreenPIN, OUTPUT);
pinMode(BluePIN, OUTPUT);
}

void loop() //collecting the incoming data and filling the buffer with it
Expand All @@ -24,17 +28,19 @@ if (Serial.available() > 0) {
int index=0;
delay(100); // let the buffer fill up
int numChar = Serial.available();
if (numChar>30) {
numChar=30;
if (numChar>22) {
numChar=22;
}
while (numChar--) {
buffer[index++] = Serial.read();
}
splitdata(buffer);
}
splitString(buffer);
}

void splitdata(char* data) { //splitting the data received based on a fixed separator (in this case the blank space " ")

}
void splitString(char* data) { //splitting the data received based on a fixed separator (in this case the blank space " ")
//Serial.print("Data entered: ");
//Serial.println(data); // display data entered/received
char* info;
info = strtok (data, " "); //using strtok split in tokens the data entered in a sequences of contiguous characters separated by the delimiter " " (empty space)
while (info != NULL) {
Expand All @@ -49,119 +55,244 @@ buffer[x]='\0';
Serial.flush();
}

//here we will store the splitted data received over the serial comunication to save our settings
//here we will store the splitted data received over the serial comunication to store our set-ups
void setallsettings(char* data) {

if (data[0] == 'm') { // select and store in the array lemode the mode (for now only Single Led Mode - 1)
if (data[0] == 'm') { // select and store in the array lemode the mode ( m1 for 3x single colour led, m2 for 1x RGB led)
int blinkdata = strtol(data+1, NULL, 10);
blinkdata = constrain(blinkdata,1,2);
transferdata[y] = blinkdata;
y=y+1;
if (y==1){ // when transferdata is full of data (we expect 2 values one for the mode and one for the number of leds between 1 and 3, for now what matters is the mode that should be 1)
if (y==1){ // when transferdata is full of data (we expect 1 data for this setting)
memcpy(ledmode, transferdata, sizeof(transferdata)); //copying transferdata to ledmode then clearing transferdata and resetting y,
for (int i=0; i<=sizeof(transferdata); i++){
transferdata[i]= '\0';
}
y=0;
}
}
if (data[0] =='d'){ //store in an array called blinkdelay the sequence of speed on which later leds will trigger
if (data[0] == 'n') { //store in an array called Nofblinks the sequence of the number of repeated trigger we want for each led and on which later leds will trigger
int blinkdata = strtol(data+1, NULL, 10);
blinkdata = constrain(blinkdata,1,1000);
blinkdata = constrain(blinkdata,1,30);
transferdata[y] = blinkdata;
y=y+1;
if (y==3){ // when transferdata is full of data (we expect 3 speeds value between 1 and 1000)
memcpy(blinkdelay, transferdata, sizeof(transferdata)); //copying transferdata to blinkdelay then clearing transferdata and resetting y,
if (y==3){ // when transferdata is full of data (we expect 3 values)
memcpy(Nofblinks, transferdata, sizeof(transferdata)); //copying transferdata to Nofblinks then clearing transferdata and resetting y,
for (int i=0; i<=sizeof(transferdata); i++){
transferdata[i]= '\0';
}
y=0;
}
}
if (data[0] == 'n') { //store in an array called blinklength the sequence of the number of repeated trigger we want for each led and on which later leds will trigger
if (data[0] == 'd') { //store in an array called blinkdelay the sequence of delays for each trigger
int blinkdata = strtol(data+1, NULL, 10);
blinkdata = constrain(blinkdata,1,30);
blinkdata = constrain(blinkdata,1,1000);
transferdata[y] = blinkdata;
y=y+1;
if (y==3){ // when transferdata is full of data (we expect 3 speeds value between 1 and 30)
memcpy(Nofblinks, transferdata, sizeof(transferdata)); //copying transferdata to Nofblinks then clearing transferdata and resetting y,
if (y==3){ // when transferdata is full of data (we expect 3 values)
memcpy(blinkdelay, transferdata, sizeof(transferdata)); //copying transferdata to blinkdelay then clearing transferdata and resetting y,
for (int i=0; i<=sizeof(transferdata); i++){
transferdata[i]= '\0';
}
y=0;
}
}

if (data[0] =='M'){ //send command M to view on serial console the currently stored value stored in ledmode[]
for (int i=0;i<=1;i++){
if(ledmode[i]!= NULL){
Serial.print("ledmode is set to: ");
Serial.println(ledmode[i]);
Serial.println(" ");
}
if (data[0] == 'U') {
int blinkdata = strtol(data+1, NULL, 10);
blinkdata = constrain(blinkdata,0,255);
transferdata[y] = blinkdata;
y=y+1;
if (y==3){ // when transferdata is full of data (we expect 3 values)
memcpy(BRIGHTU, transferdata, sizeof(transferdata)); //copying transferdata to BRIGHTU then clearing transferdata and resetting y,
transferdata[0]= '\0';
y=0;
}
}
if (data[0] =='D'){ //send command S to view on serial console the currently stored value stored in blinkdelay[]
for (int i=0;i<=2;i++){
if(blinkdelay[i]!= NULL){
Serial.print("blinkdelay for led ");
Serial.print(i+1);
Serial.print(" is:");
Serial.println(blinkdelay[i]);
if (i==2){
Serial.println(" ");}
}
if (data[0] == 'F') {
int blinkdata = strtol(data+1, NULL, 10);
blinkdata = constrain(blinkdata,0,255);
transferdata[y] = blinkdata;
y=y+1;
if (y==3){ // when transferdata is full of data (we expect 3 values)
memcpy(BRIGHTF, transferdata, sizeof(transferdata)); //copying transferdata to BRIGHTF then clearing transferdata and resetting y,
transferdata[0]= '\0';
y=0;
}
}

if (data[0] =='N'){ //send command L to view on serial console the currently stored value stored in Nofblinks[]
for (int i=0;i<=2;i++){
if(Nofblinks[i]!= NULL){
if (data[0] == 'P') {
int blinkdata = strtol(data+1, NULL, 10);
blinkdata = constrain(blinkdata,0,255);
transferdata[y] = blinkdata;
y=y+1;
if (y==3){ // when transferdata is full of data (we expect 3 values)
memcpy(BRIGHTP, transferdata, sizeof(transferdata)); //copying transferdata to BRIGHTP then clearing transferdata and resetting y,
transferdata[0]= '\0';
y=0;
}
}
if (data[0] == '?'){ //send command set to view on serial all the current setups
Serial.println("Current Settings: ");
Serial.println("---------------------------------------------------- ");
Serial.println(" ");
if(ledmode[0]== 1){
Serial.println("ledmode is set to: 3x single colour LED ");
Serial.println(" ");
for (int i=0;i<=2;i++){
Serial.print("Nofblinks for led");
Serial.print(i+1);
Serial.print(" is:");
Serial.println(Nofblinks[i]);
Serial.print(Nofblinks[i]);
Serial.println(" Blinks");
if (i==2){
Serial.println(" ");
}
}
for (int i=0;i<=2;i++){
Serial.print("blinkdelay for led ");
Serial.print(i+1);
Serial.print(" is:");
Serial.print(blinkdelay[i]);
Serial.println(" Millis");
if (i==2){
Serial.println(" ");}
}
Serial.println(" ");
}
}
}
if(ledmode[0]==2){
Serial.println("ledmode is set to: 1x RGB LED ");
Serial.println(" ");

Serial.print("number of blinks for upvote trigger is: ");
Serial.print(Nofblinks[0]);
Serial.println(" Blinks");
Serial.print("number of blinks for follower trigger is: ");
Serial.print(Nofblinks[1]);
Serial.println(" Blinks");
Serial.print("number of blinks for post trigger is: ");
Serial.print(Nofblinks[2]);
Serial.println(" Blinks");
Serial.println(" ");

Serial.print("blinkdelay for upvote trigger is: ");
Serial.print(blinkdelay[0]);
Serial.println(" Millis");
Serial.print("blinkdelay for follower trigger is: ");
Serial.print(blinkdelay[1]);
Serial.println(" Millis");
Serial.print("blinkdelay for post trigger is: ");
Serial.print(blinkdelay[2]);
Serial.println(" Millis");
Serial.println(" ");

Serial.println("RGB value for upvote trigger is set to");
Serial.println(" ");
Serial.print("R= ");
Serial.println(BRIGHTU[0]);
Serial.print("G= ");
Serial.println(BRIGHTU[1]);
Serial.print("B= ");
Serial.println(BRIGHTU[2]);
Serial.println("");

Serial.println("RGB value for follower trigger is set to");
Serial.println(" ");
Serial.print("R= ");
Serial.println(BRIGHTF[0]);
Serial.print("G= ");
Serial.println(BRIGHTF[1]);
Serial.print("B= ");
Serial.println(BRIGHTF[2]);
Serial.println("");

Serial.println("RGB value for post trigger is set to");
Serial.println(" ");
Serial.print("R= ");
Serial.println(BRIGHTP[0]);
Serial.print("G= ");
Serial.println(BRIGHTP[1]);
Serial.print("B= ");
Serial.println(BRIGHTP[2]);
Serial.println("");
}
}
}
}
}

void setLEDon(char* data) {
if(ledmode[0]==1){
if (data[0] == 'u') { //if i receive the command 'u' from serial (upvote) and if ledmode[0] is set to 1 (standard led mode) do the blinking
//if i receive the command u from serial (upvote)
if (data[0] == 'u') {
if(ledmode[0]==1){ //and if ledmode[0] is set to 1 (3x single colour led mode)
for (int a= 0; a< Nofblinks[0]; a++){
digitalWrite(LED_ONE, HIGH);
digitalWrite(RedPIN, HIGH);
delay(blinkdelay[0]);
digitalWrite(LED_ONE, LOW);
digitalWrite(RedPIN, 0);
delay(blinkdelay[0]);
}
Serial.println("you got an upvote ");
Serial.println(" ");
}
}
if(ledmode[0]==2){
for (int a= 0; a< Nofblinks[0]; a++){
analogWrite(RedPIN, BRIGHTU[0]);
analogWrite(GreenPIN, BRIGHTU[1]);
analogWrite(BluePIN, BRIGHTU[2]);
delay(blinkdelay[0]);
analogWrite(RedPIN, 0);
analogWrite(GreenPIN, 0);
analogWrite(BluePIN, 0);
delay(blinkdelay[0]);
}
}

if (data[0] == 'f') { //if i receive the command f from serial (follower) and if ledmode[0] is set to 1 (standard led mode) do the blinking
for (int a= 0; a< Nofblinks[1]; a++){
digitalWrite(LED_TWO, HIGH);
delay(blinkdelay[1]);
digitalWrite(LED_TWO, LOW);
delay(blinkdelay[1]);
}
Serial.println("you got a new follower ");
Serial.println(" ");
Serial.println("you got an upvote ");
Serial.println(" ");
}
//if i receive the command f from serial (follower)
if (data[0] == 'f') {
if(ledmode[0]==1){ //and if ledmode[0] is set to 1 (standard led mode)
for (int a= 0; a< Nofblinks[1]; a++){
digitalWrite(GreenPIN, HIGH);
delay(blinkdelay[1]);
digitalWrite(GreenPIN, 0);
delay(blinkdelay[1]);
}
}
if(ledmode[0]==2){ //and if ledmode[0] is set to 2 (1x RGB led mode)
for (int a= 0; a< Nofblinks[1]; a++){
analogWrite(RedPIN, BRIGHTF[0]);
analogWrite(GreenPIN, BRIGHTF[1]);
analogWrite(BluePIN, BRIGHTF[2]);
delay(blinkdelay[1]);
analogWrite(RedPIN, 0);
analogWrite(GreenPIN, 0);
analogWrite(BluePIN, 0);
delay(blinkdelay[1]);
}
}
Serial.println("you got a new follower ");
Serial.println(" ");
}


if (data[0] == 'p') { //if i receive the command p from serial (new post) and if ledmode[0] is set to 1 (standard led mode) do the blinking
for (int a= 0; a< Nofblinks[2]; a++){
digitalWrite(LED_THREE, HIGH);
delay(blinkdelay[2]);
digitalWrite(LED_THREE, LOW);
delay(blinkdelay[2]);
}
Serial.println("there is a new post");
Serial.println(" ");
}
if (data[0] == 'p') { //if i receive the command p from serial (new post) and if ledmode[0] is set to 1 (standard led mode)
if(ledmode[0]==1){ //and if ledmode[0] is set to 1 (standard led mode)
for (int a= 0; a< Nofblinks[2]; a++){
digitalWrite(BluePIN, HIGH);
delay(blinkdelay[2]);
digitalWrite(BluePIN, 0);
delay(blinkdelay[2]);
}
}
if(ledmode[0]==2){ //and if ledmode[0] is set to 2 (1x RGB led mode)
for (int a= 0; a< Nofblinks[2]; a++){
analogWrite(RedPIN, BRIGHTP[0]);
analogWrite(GreenPIN, BRIGHTP[1]);
analogWrite(BluePIN, BRIGHTP[2]);
delay(blinkdelay[2]);
analogWrite(RedPIN, 0);
analogWrite(GreenPIN, 0);
analogWrite(BluePIN, 0);
delay(blinkdelay[2]);
}
}
Serial.println("ther is a new post ");
Serial.println(" ");
}
}

Binary file added Arduinowiring1xRGBled.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Arduinowiring3xSingleled.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Arduinowiring3xSingleled.png
Binary file not shown.
Binary file added Thumbs.db
Binary file not shown.

0 comments on commit 0c069a8

Please sign in to comment.