REPresent

Showcase (no instructions)110
REPresent

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
Adafruit NeoPixel Digital RGB LED Strip - White 60 LED - WHITE
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Infrared distance sensor
×1

Hand tools and fabrication machines

Laser cutter (generic)
Laser cutter (generic)

Story

Read more

Custom parts and enclosures

Laser Cut file for project box

Laser cut file for sensor box

Schematics

Circuit diagram

Cp prov3%20circuit%20diagram

Code

Arduino code for REPresent

Arduino
// This code is for the REPresent project. This is not production ready, but only meant for the demo purposes.
// To make this production ready, here are the things that need to be changed:
// 1. Sync the arduino time with an external service
// 2. Instead of the current demo teamTotals, calculate the correct values based on which team is active at that time
// 3. Scale the teamTotals to the LED strips. 
// In addition to this, it would be good to add an extra circuit which displayed the current user's rep total in a separate LED display. This would boost the individual's self-motivation, in addition to the team motivation

#include <Adafruit_NeoPixel.h>
#include <TimeLib.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define TIME_HEADER  "T"   // Header tag for serial time sync message
#define TIME_REQUEST  7    // ASCII bell character requests a time sync message 
//#define TIME_OUTPUT  13 // for LED to show whether time is synced or not.

#define PIN1 9
#define PIN2 8
#define PIN3 7
#define PIN4 6
#define IRSIGNAL 10

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strips[] = {Adafruit_NeoPixel(15, PIN1, NEO_GRB + NEO_KHZ800), Adafruit_NeoPixel(15, PIN2, NEO_GRB + NEO_KHZ800), Adafruit_NeoPixel(15, PIN3, NEO_GRB + NEO_KHZ800), Adafruit_NeoPixel(15, PIN4, NEO_GRB + NEO_KHZ800)};

//Adafruit_NeoPixel s = Adafruit_NeoPixel(15, PIN, NEO_GRB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.

int teamTotal[4];
int activeTeam;
int blinker;


void setup() {

  for(int i=0; i<4;i++){
    strips[i].begin();
    strips[i].show();

// this is a setup only for testing the LED strips
//    teamTotal[i] = 2+ i*2;
    // end of test setup
  }
  teamTotal[0] = 12;
  teamTotal[1] = 14;
  teamTotal[2] = 13;
  teamTotal[3] = 1;
  
  blinker = 0;

// test setup for active team 2
  activeTeam = 1;

//  IR sensor setup
  pinMode(IRSIGNAL, INPUT);
  Serial.begin(9600);

// time setup
//  pinMode(TIME_OUTPUT, OUTPUT);
//  setSyncProvider( requestSync);  //set function to call when sync required
//  Serial.println("Waiting for sync message");

}

void loop() {
//  if (Serial.available()) {
//    processSyncMessage();
//  }
//  if (timeStatus()!= timeNotSet) {
//    
//    represent();
//    delay(1000);
//  }

  represent();
  
}

void represent() {

//  find out which team is active
// For testing, activeTeam = 1
  int hr = hour();
  if ( hr >= 6 && hr <11)
    activeTeam = 0;
  else if (hr >= 11 && hr < 16)
    activeTeam = 1;
  else if (hr >= 16 && hr < 21)
    activeTeam = 2;
  else if (hr >= 21 || hr < 1)
    activeTeam = 3;

//  find if IR signal was interrupted. If interrupted, it is a REP.


//  if REP
//    increase teamTotal of active team

  bool rep = isREP();
  
  if(rep){
    teamTotal[activeTeam]++;
    Serial.print("teamTotal[activeTeam] : ");
    Serial.println(teamTotal[activeTeam]);
  }

// light up the LED strips
  for(int i=0; i<4; i++){
    lightup(i, teamTotal[i], rep);
  }

  if(rep) {
    // blink the last LED in the active team
    blink(teamTotal[activeTeam], activeTeam);
  }
}

void blink(int lastLED, int strip){
//  for (int i=0; i<5; i++){
//    strips[strip].setPixelColor(lastLED, 0, 0, 0);
//    delay(500);
//    strips[strip].setPixelColor(lastLED, 0, 255, 0);
//    Serial.println("Blink you #$%^&");
//  }
}

bool isREP(){
  bool itIs = false;
  if(!digitalRead(IRSIGNAL))
  {
    Serial.println("Is totally a rep");
    itIs = true;
  }
  while(!digitalRead(IRSIGNAL));
  Serial.println("Not a rep!");

  return itIs;
}

void lightup(int strip, int total, bool rep){
  uint16_t end_led = 15;
  
  for(uint16_t i= 0; i<total; i++) {
    if (activeTeam == strip){
        strips[strip].setPixelColor(i, 0, 255, 0);
//        if(rep){
//          strips[strip].setPixelColor(i, 0, 0, 0);
//        }
    }
    else {
      strips[strip].setPixelColor(i, 0, 0, 255);
    }
  }
//
//  if(activeTeam == strip){
//    delay(50);
//  }

  strips[strip].show();

//  printTime();
}

void processSyncMessage() {
  unsigned long pctime;
  const unsigned long DEFAULT_TIME = 1357041600; // Jan 1 2013

  if(Serial.find(TIME_HEADER)) {
     pctime = Serial.parseInt();
     if( pctime >= DEFAULT_TIME) { // check the integer is a valid time (greater than Jan 1 2013)
       setTime(pctime); // Sync Arduino clock to the time received on the serial port
     }
  }
}

time_t requestSync()
{
  Serial.write(TIME_REQUEST);  
  return 0; // the time will be sent later in response to serial mesg
}

Credits

Alice Suyoung Chung

Alice Suyoung Chung

4 projects • 2 followers
Contact
Wendy Ho

Wendy Ho

2 projects • 1 follower
Contact
Samudra Neelam Bhuyan

Samudra Neelam Bhuyan

3 projects • 1 follower
Contact
Hasnain Nazar

Hasnain Nazar

3 projects • 1 follower
Contact

Comments