Violet李遂志Meilily Livitamin CC
Published © GPL3+

Make an Interactive Color Matrix with Seeeduino/Arduino

This is an interactive art project made by a Seeeduino 4.2 boards, looking good and easy to do!

BeginnerFull instructions provided8 hours4,040

Things used in this project

Hardware components

Seeed Studio Seeeduino V4.2
×1
Seeed Studio ProtoBoard
×1

Story

Read more

Code

Arduino Code

Arduino
#include <Adafruit_NeoPixel.h>

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

#define PIN 5

#define NUM_LEDS 64

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
uint8_t theLastLED = 0;

const uint8_t  LineList[8] =   { 2, 3, 4, 6, 7, 8, 9,10};
const uint8_t   RowList[8] =   {11,12,A0,A1,A2,A3,A4,A5};
static uint8_t ledST[64] = {0};

void setup() {
  // put your setup code here, to run once:
  pinMode(LED_BUILTIN, OUTPUT);
  for(uint8_t i = 0; i<8; i++){
    pinMode(LineList[i], INPUT);
    pinMode( RowList[i], INPUT);
  }

  strip.begin();
//  strip.setPixelColor(0, 0x2020d0);
  strip.show(); // Initialize all pixels to 'off'
  Serial.begin(115200);
}

void loop() {
  // put your main code here, to run repeatedly:
    uint8_t touchKey;
    touchKey = getCrossNum();
//  lightOn(touchKey);
//   lightKeep(random(64));
    lightKeep(touchKey);
 
  
}

void testAllPin(){
  uint8_t lineVal = 0, rowVal = 0;
  for(uint8_t i = 0; i<8; i++){
    if(digitalRead(LineList[i]) == LOW){
      lineVal +=1;
    } 
    if(digitalRead(RowList[i]) == LOW){
      rowVal +=1;
    } 
  }
  if((lineVal + rowVal) > 0) digitalWrite(LED_BUILTIN, HIGH);
  else digitalWrite(LED_BUILTIN, LOW);
}


/***
 *  0xff: means no cross have been touched
 *  0~63 means which have been touched
***/
uint8_t getCrossNum(){
  uint8_t retval = 0xff;
  uint8_t lineVal = 0xff, rowVal = 0xff;
  for(uint8_t i = 0; i<8; i++){
    if(digitalRead(LineList[i]) == LOW){
      lineVal = i;
      break;
    } 
  }
  if(lineVal < 8){
    for(uint8_t j = 0; j<8; j++){
      if(digitalRead(RowList[j]) == LOW){
        rowVal = j;
        break;
      } 
    }    
  }
  if(rowVal < 8){
    if(lineVal %2 == 0){
      retval = rowVal + (8 * lineVal);
    }
    else{
      retval = (7 - rowVal) + (8 * lineVal);
    }
  }
  else retval = 0xff;
  delay(100);
  return retval;
}

/***
 *  0xff: means no cross have been touched
 *  0~63 means which have been touched
***/
void lightOn(uint8_t num)
{
  if(num == theLastLED) return;
  
  if(num  < 64 ){
    strip.setPixelColor(num, 0x2020d0);
    strip.show();
    theLastLED = num;
  }
  else{
    strip.setPixelColor(theLastLED, 0);
    strip.show();
    theLastLED = 0xff;
  }
}

/***
 *  0xff: means no cross have been touched
 *  0~63 means which have been touched
***/
void lightKeep(uint8_t num){
  static uint8_t lastNum = 0xff;
  if(num >= 64) return;
  if(num == lastNum) return;
  lastNum = num;
  
  if(ledST[num] != 0){
    ledST[num] = 0;
    strip.setPixelColor(num, 0);
    strip.show();
  }
  else{
    ledST[num] = 1;
    uint8_t color[3] = {0x00};
    uint32_t RGB = 0x000000;
    color[0] = uint8_t(random(256));
    color[1] = uint8_t(random(256));
    color[2] = uint8_t(random(256));
    RGB = color[0]+(color[1]<<8)+(color[2]<<16);
    strip.setPixelColor(num, RGB);
    strip.show();
    Serial.println(num);
  }
  
}

Credits

Violet

Violet

5 projects • 9 followers
#tinybutstrong #optimistic #language
李遂志

李遂志

1 project • 2 followers
Meilily Li

Meilily Li

3 projects • 16 followers
Love all things related to creativeness.
vitamin CC

vitamin CC

1 project • 5 followers

Comments