Vijay J Samuel
Published © MIT

Clip-ON Move-ON

Clip-ON is a backpack attachment, that will monitor the vicinity of the user and alerts anybody who does not maintain social distancing.

IntermediateFull instructions provided5 hours2,083
Clip-ON Move-ON

Things used in this project

Hardware components

Arduino MKR WiFi 1010
Arduino MKR WiFi 1010
×1
RGB LED Pixel Matrix, NeoPixel NeoMatrix
RGB LED Pixel Matrix, NeoPixel NeoMatrix
×1
SparkFun Distance Sensor Breakout - 4 Meter, VL53L1X (Qwiic)
×1
Battery, 3.7 V
Battery, 3.7 V
×1

Software apps and online services

Arduino IDE
Arduino IDE
MIT App Inventor
MIT App Inventor

Story

Read more

Schematics

Schematic

It's very straight Forward

Code

Main Arduino Code

C/C++
The main Arduino code
/*
 * Clip-ON Move-ON
 * Copyright (C) 2020 Vijay J Samuel.  All Rights Reserved.
 *
 * Author: Vijay J Samuel
 * Email: vijayjoseph.official@gmail.com
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */


 
#include <Scheduler.h>
#include "BLE_Handler.h"
#include "Led_Handler.h"
#include "Lidar_Handler.h"
#include "Sprint.h"



void setup() {
  // put your setup code here, to run once:

  BLE_Initialize();
  LED_Initialize();
  LIDAR_Initialize();
  
  Serial.begin(115200);
  Scheduler.startLoop(BLE_Routine);
  Scheduler.startLoop(LED_Routine);
  Scheduler.startLoop(LIDAR_Routine);
}

void loop() {
  // put your main code here, to run repeatedly:
  yield();
}

BLE_Handler.h

C/C++
This file declares the variables and functions for BLE
/*
 * Clip-ON Move-ON
 * Copyright (C) 2020 Vijay J Samuel.  All Rights Reserved.
 *
 * Author: Vijay J Samuel
 * Email: vijayjoseph.official@gmail.com
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */


#ifndef _BLE_HANDLER_H_
#define _BLE_HANDLER_H_

#include <Arduino.h>
#include <ArduinoBLE.h>
#include <Scheduler.h>
#include "Sprint.h"


const int ledPin = LED_BUILTIN; 

void BLE_Initialize();
void BLE_Routine();

#endif

LIDAR_Handler.h

C/C++
This file declares the variables and functions for ToF sensor
/*
 * Clip-ON Move-ON
 * Copyright (C) 2020 Vijay J Samuel.  All Rights Reserved.
 *
 * Author: Vijay J Samuel
 * Email: vijayjoseph.official@gmail.com
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */


#ifndef _LIDAR_HANDLER_H_
#define _LIDAR_HANDLER_H_

#include <Arduino.h>
#include <Scheduler.h>
#include <Wire.h>
#include "SparkFun_VL53L1X.h" 
#include "Sprint.h"



void LIDAR_Initialize();
void LIDAR_Routine();

bool signalStatus();
#endif

LED_Handler.h

C/C++
This file declares the variables and functions for LED Matrix
/*
 * Clip-ON Move-ON
 * Copyright (C) 2020 Vijay J Samuel.  All Rights Reserved.
 *
 * Author: Vijay J Samuel
 * Email: vijayjoseph.official@gmail.com
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */


#ifndef _LED_HANDLER_H_
#define _LED_HANDLER_H_

#include <Arduino.h>
#include <Scheduler.h>
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#include "Sprint.h"

#define MATRIX_PIN 7

//#define BRIGHTNESS 1

#define mw 8
#define mh 8


#define LED_BLACK    0

#define LED_RED_VERYLOW   (3 <<  11)
#define LED_RED_LOW     (7 <<  11)
#define LED_RED_MEDIUM    (15 << 11)
#define LED_RED_HIGH    (31 << 11)

#define LED_GREEN_VERYLOW (1 <<  5)   
#define LED_GREEN_LOW     (15 << 5)  
#define LED_GREEN_MEDIUM  (31 << 5)  
#define LED_GREEN_HIGH    (63 << 5)  

#define LED_BLUE_VERYLOW  3
#define LED_BLUE_LOW    7
#define LED_BLUE_MEDIUM   15
#define LED_BLUE_HIGH     31

#define LED_ORANGE_VERYLOW  (LED_RED_VERYLOW + LED_GREEN_VERYLOW)
#define LED_ORANGE_LOW    (LED_RED_LOW     + LED_GREEN_LOW)
#define LED_ORANGE_MEDIUM (LED_RED_MEDIUM  + LED_GREEN_MEDIUM)
#define LED_ORANGE_HIGH   (LED_RED_HIGH    + LED_GREEN_HIGH)

#define LED_PURPLE_VERYLOW  (LED_RED_VERYLOW + LED_BLUE_VERYLOW)
#define LED_PURPLE_LOW    (LED_RED_LOW     + LED_BLUE_LOW)
#define LED_PURPLE_MEDIUM (LED_RED_MEDIUM  + LED_BLUE_MEDIUM)
#define LED_PURPLE_HIGH   (LED_RED_HIGH    + LED_BLUE_HIGH)

#define LED_CYAN_VERYLOW  (LED_GREEN_VERYLOW + LED_BLUE_VERYLOW)
#define LED_CYAN_LOW    (LED_GREEN_LOW     + LED_BLUE_LOW)
#define LED_CYAN_MEDIUM   (LED_GREEN_MEDIUM  + LED_BLUE_MEDIUM)
#define LED_CYAN_HIGH   (LED_GREEN_HIGH    + LED_BLUE_HIGH)


#define LED_WHITE_VERYLOW (LED_RED_VERYLOW + LED_GREEN_VERYLOW + LED_BLUE_VERYLOW)
#define LED_WHITE_LOW   (LED_RED_LOW     + LED_GREEN_LOW     + LED_BLUE_LOW)
#define LED_WHITE_MEDIUM  (LED_RED_MEDIUM  + LED_GREEN_MEDIUM  + LED_BLUE_MEDIUM)
#define LED_WHITE_HIGH    (LED_RED_HIGH    + LED_GREEN_HIGH    + LED_BLUE_HIGH)






static const uint8_t PROGMEM
    mono_bmp[][8] =
    {

      {
      B00011000,
      B00000000,
      B00000000,
      B00000000,
      B00000000,
      B00000000,           
      B00000000,  
      B00000000,
      
                      },

      {
      
      B00111100,
      B00011000,
      B00000000,
      B00000000,
      B00000000,
      B00000000,           
      B00000000,  
      B00000000,

                      },

      {
      B01111110,  
      B00111100,
      B00011000,  
      B00000000,
      B00000000,
      B00000000,           
      B00000000,  
      B00000000,     
                  },

      {
      B11111111,
      B01111110,
      B00111100,
      B00011000,  
      B00000000,
      B00000000,           
      B00000000,  
      B00000000,
                      },

      {
      B00011000,
      B11111111,
      B01111110,
      B00111100,
      B00011000,
      B00000000,           
      B00000000,  
      B00000000,
            },
 {   
      B00011000,
      B00011000,
      B11111111,
      B01111110,
      B00111100,
      B00011000,
      B00000000,  
      B00000000,
            },


        {   
      B00011000,
      B00011000,
      B00011000,
      B11111111,
      B01111110,
      B00111100,
      B00011000,
      B00000000,
      
            },
            
  {   
      B00011000,
      B00011000,
      B00011000,
      B00011000,
      B11111111,
      B01111110,
      B00111100,
      B00011000,
       },


{
      B11000001,
      B11100111,
      B01111110,
      B00111100,
      B00111100,           
      B01111110,  
      B11100111,
      B11000011,
                      },

                      {
      B00000000,
      B01100110,
      B11111111,
      B11111111,
      B01111110,           
      B00111100,  
      B00011000,
      B00000000,
                      },
                      
  {   // 1: checkered 2
      B00000000,
      B00111000,
      B00100010,
      B10000010,
      B01000001,
      B10000010,
      B00100010,
      B00111000,
      },

      {   // 1: checkered 2
      B00000000,
      B00000000,
      B00000000,
      B00000000,
      B00010000,
      B00000000,
      B00000000,
      B00000000,
      },

  {   // 2: smiley
      B00111100,
      B01000010,
      B10100101,
      B10000001,
      B10100101,
      B10011001,
      B01000010,
      B00111100 },

  {   // 3: neutral
      B00111100,
      B01000010,
      B10100101,
      B10000001,
      B10111101,
      B10000001,
      B01000010,
      B00111100 },

  {   // 4; frowny
      B00111100,
      B01000010,
      B10100101,
      B10000001,
      B10011001,
      B10100101,
      B01000010,
      B00111100 },
    };



void display_bitmap (uint8_t bmp_num, uint16_t color);
void display_rgbBitmap (uint8_t bmp_num);
void fixdrawRGBBitmap (int16_t x, int16_t y, const uint16_t *bitmap, int16_t w, int16_t h) ;
void LED_Initialize ();
void LED_Routine ();
void display_scrollText(char* text1);

#endif

BLE_Handler.cpp

C/C++
This file handles the BLE routines
/*
 * Clip-ON Move-ON
 * Copyright (C) 2020 Vijay J Samuel.  All Rights Reserved.
 *
 * Author: Vijay J Samuel
 * Email: vijayjoseph.official@gmail.com
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */


#include "BLE_Handler.h"

BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service
BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
BLEByteCharacteristic brightnessCharacteristic("19B10002-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
BLEByteCharacteristic scrollingCharacteristic("19B10003-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
BLEStringCharacteristic textCharacteristic("19B10004-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite,20);

extern int brightness ;
extern bool power;
extern bool turnOnText;
extern bool turnOffText;
extern bool scrolling;
extern String scrollingText;
void BLE_Initialize(){
  
  pinMode(ledPin, OUTPUT);
  
  if (!BLE.begin()) 
    Sprintln("starting BLE failed!");
  
  BLE.setLocalName("CLIP-ON MOVE-ON");
  BLE.setAdvertisedService(ledService);
  
  ledService.addCharacteristic(switchCharacteristic);
  ledService.addCharacteristic(brightnessCharacteristic);
  ledService.addCharacteristic(scrollingCharacteristic);
  ledService.addCharacteristic(textCharacteristic);
  BLE.addService(ledService);

  switchCharacteristic.writeValue(0);
  brightnessCharacteristic.writeValue(0);
  scrollingCharacteristic.writeValue(0);
  BLE.advertise();

  Sprintln("Clip-ON Move-ON Availabe to Connect");
  }

void BLE_Routine(){
  
  BLEDevice central = BLE.central();
   yield();
  if (central) {
  Sprint("Connected to Device: ");
//  Serial.println("Test");
  Sprintln(central.address());

  while (central.connected()) {
    if (switchCharacteristic.written()) {
      if (switchCharacteristic.value()) {   // any value other than 0
        Sprintln("POWER ON");
        power = true;
        turnOnText =  true;
        digitalWrite(ledPin, HIGH);         // will turn the LED on
      } else {                              // a 0 value
        Sprintln(F("POWER OFF"));
        power = false;
        turnOffText =  true;
        digitalWrite(ledPin, LOW);          // will turn the LED off
      }
    }

    if (brightnessCharacteristic.written()) {
      brightness = brightnessCharacteristic.value();
      Sprintln(brightness);
    }

    if (scrollingCharacteristic.written()) {
      scrolling = scrollingCharacteristic.value();
      Sprintln(scrolling);
    }

    if (textCharacteristic.written()) {
      scrollingText = textCharacteristic.value();
      Sprintln(scrollingText);
    }
    yield();
  }


  Sprint(F("Disconnected from central: "));
  Sprintln(central.address());
  yield();
}
  }  

LIDAR_Handler.cpp

C/C++
This file handles the ToF sensor routines
/*
 * Clip-ON Move-ON
 * Copyright (C) 2020 Vijay J Samuel.  All Rights Reserved.
 *
 * Author: Vijay J Samuel
 * Email: vijayjoseph.official@gmail.com
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */


#include "Lidar_Handler.h"

SFEVL53L1X distanceSensor;

extern int distance = 0;
extern int prev_distance = 0;
extern int power;
extern int led_sequence;

void LIDAR_Initialize(){
  
  Wire.begin();

  if (distanceSensor.begin() != 0) //Begin returns 0 on a good init
  {
    Sprintln("TOF Sensor failed to begin. Please check wiring. Freezing...");

  }
  ("TOF Sensor online!");
  }

void LIDAR_Routine(){
  yield();
  if(power){
  prev_distance = distance;
  distanceSensor.startRanging(); //Write configuration block of 135 bytes to setup a measurement
  while (!distanceSensor.checkForDataReady())
  {
    delay(1);
  }
  distance = distanceSensor.getDistance(); //Get the result of the measurement from the sensor
  distanceSensor.clearInterrupt();
  distanceSensor.stopRanging();


  if(signalStatus()){

//  Sprint("Distance(mm): ");
//  Sprint (distance);


  int slope = distance - prev_distance;

//  Sprint("\tSlope: ");
//  Sprint(slope);

  
  }

  else{
    Sprint("Signal Fail");
    }
  
//  Sprintln();
  if(distance < 1500) {
    led_sequence = 1;
//    Sprintln("             Loop Entered");
    }

  if(distance > 1500) {
    led_sequence = 0;
//    Sprintln("             Loop2 Entered");
    }  
  yield();
  
  }  

} 


bool signalStatus(void){
  byte rangeStatus = distanceSensor.getRangeStatus();
  if(rangeStatus == 0)
    return 1;
  else
    return 0;  
  }  

LED_Handler.cpp

C/C++
This file handles the LED Matrix routines
/*
 * Clip-ON Move-ON
 * Copyright (C) 2020 Vijay J Samuel.  All Rights Reserved.
 *
 * Author: Vijay J Samuel
 * Email: vijayjoseph.official@gmail.com
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */


#include "Led_Handler.h"

int cross = 2;
extern int brightness = 1;
extern bool power = false;
extern bool turnOnText = false;
extern bool turnOffText = false;
extern bool scrolling = false;
extern String scrollingText = "Wear Mask";
//char textToScroll;
extern int distance;
extern int prev_distance;
extern int led_sequence = 0;
static uint8_t pixmap_count = ((mw+7)/8) * ((mh+7)/8);
bool ledOn = false;

Adafruit_NeoMatrix *matrix = new Adafruit_NeoMatrix(mw, mh, MATRIX_PIN,
  NEO_MATRIX_TOP     + NEO_MATRIX_RIGHT +
  NEO_MATRIX_COLUMNS + NEO_MATRIX_PROGRESSIVE,
  NEO_GRB            + NEO_KHZ800);

const uint16_t colors[] = {
  matrix->Color(255, 0, 0), matrix->Color(0, 255, 0), matrix->Color(0, 0, 255) };

int x    = matrix->width();
int pass = 0;  
void LED_Initialize(){
  matrix->begin();
  matrix->setTextWrap(false);
  matrix->setBrightness(brightness);
  matrix->setTextColor(colors[0]);
  }

void LED_Routine(){
  yield();
//  display_scrollText("VIJAY");


  
  if(turnOffText){
    
    Sprintln("SHUTDOWN SMILEY");
    display_bitmap(14, LED_GREEN_HIGH);
    delay(2000); 
    matrix->fillScreen(LED_BLACK);
    matrix->show();
    turnOffText = false;
    }  
    
  if(power){

   if(!scrolling){
      if(ledOn){
        ledOn = false;
        matrix->fillScreen(LED_BLACK);
        matrix->show();
        }

    }
   if(scrolling){
//      const char* disp = scrollingText.c_str();
      char *s2 = new char[scrollingText.length()+1];
      strcpy(s2, scrollingText.c_str());
      ledOn = true;
      display_scrollText(s2);
      yield();
   }
  if(turnOnText){
    Sprintln("STARTUP SMILEY");
    display_bitmap(12, LED_BLUE_HIGH);
    delay(2000); 
    matrix->fillScreen(LED_BLACK);
    matrix->show();
    turnOnText = false;
    }  
  
  if(led_sequence == 1){
  matrix->setBrightness(brightness);
  Serial.println(led_sequence);

      
  for(int i=0;i<cross;i++){
    Sprintln("Displaying Red Cross");
    ledOn = true;
    display_bitmap(8,LED_RED_HIGH);
    delay(200);
    matrix->fillScreen(LED_BLACK);
    matrix->show();
    delay(200);
    }
      
  while(distance < 1500){
    Sprintln("Displaying Green Arrow");
    for (uint8_t i=0; i<8; i++){
      display_bitmap(i, LED_GREEN_HIGH);
      delay(100);
      
      }
  ledOn = true;

    }
  Sprintln("Displaying Heart");
  display_bitmap(9, LED_PURPLE_HIGH);
  delay(1000); 
  led_sequence = 0;
  matrix->fillScreen(LED_BLACK);
  matrix->show();
    }

  if(led_sequence == 0 ){
    if(ledOn == true){
    matrix->fillScreen(LED_BLACK);
    matrix->show();
    ledOn = false;
    yield();
    }
    }

    }
  }


void display_bitmap(uint8_t bmp_num, uint16_t color) { 
  static uint16_t bmx,bmy;

  // Clear the space under the bitmap that will be drawn as
  // drawing a single color pixmap does not write over pixels
  // that are nul, and leaves the data that was underneath
  matrix->fillRect(bmx,bmy, bmx+8,bmy+8, LED_BLACK);
  matrix->drawBitmap(bmx, bmy, mono_bmp[bmp_num], 8, 8, color);
  bmx += 8;
  if (bmx >= mw) bmx = 0;
  if (!bmx) bmy += 8;
  if (bmy >= mh) bmy = 0;
  matrix->show();
}

void fixdrawRGBBitmap(int16_t x, int16_t y, const uint16_t *bitmap, int16_t w, int16_t h) {
    uint16_t RGB_bmp_fixed[w * h];
    for (uint16_t pixel=0; pixel<w*h; pixel++) {
  uint8_t r,g,b;
  uint16_t color = pgm_read_word(bitmap + pixel);

  //Serial.print(color, HEX);
  b = (color & 0xF00) >> 8;
  g = (color & 0x0F0) >> 4;
  r = color & 0x00F;
  //Serial.print(" ");
  //Serial.print(b);
  //Serial.print("/");
  //Serial.print(g);
  //Serial.print("/");
  //Serial.print(r);
  //Serial.print(" -> ");
  // expand from 4/4/4 bits per color to 5/6/5
  b = map(b, 0, 15, 0, 31);
  g = map(g, 0, 15, 0, 63);
  r = map(r, 0, 15, 0, 31);
  //Serial.print(r);
  //Serial.print("/");
  //Serial.print(g);
  //Serial.print("/");
  //Serial.print(b);
  RGB_bmp_fixed[pixel] = (r << 11) + (g << 5) + b;
  //Serial.print(" -> ");
  //Serial.println(RGB_bmp_fixed[pixel], HEX);
    }
    matrix->drawRGBBitmap(x, y, RGB_bmp_fixed, w, h);
}

void display_scrollText(char* text1){
  matrix->fillScreen(0);
  matrix->setCursor(x, 0);
  matrix->print(F(text1));
  if(--x < -36) {
    x = matrix->width();
    if(++pass >= 3) pass = 0;
//    matrix->setTextColor(colors[pass]);
  }
  matrix->show();
  delay(100);
  }

Sprint.h

C/C++
This file handles the debugging
/*
 * Clip-ON Move-ON
 * Copyright (C) 2020 Vijay J Samuel.  All Rights Reserved.
 *
 * Author: Vijay J Samuel
 * Email: vijayjoseph.official@gmail.com
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */


#define ENABLE_PRINT

#ifdef ENABLE_PRINT
#define Sprintln(a) (Serial.println(a))
#define Sprint(a) (Serial.print(a))
#endif

#ifndef ENABLE_PRINT
#define Sprintln(a) 
#define Sprint(a) 
#endif

Credits

Vijay J Samuel

Vijay J Samuel

1 project • 4 followers
Hobbyist maker :)

Comments