5-in-5_Day1_Unicorn Striking through the Grass

“n-in-n”, a tradition around ITP, where students complete n project in n day, over a certain number of days.

In this case, 5 days, 5 projects. Besides participating bunch of workshops held by amazing 2nd-years, for my Day1 project, I was thinking about doing StormLighter with this tutorial, but cut it off because of the shortage of materials. So I moved on to other new stuff: Capacity Sensing Library, which I always wanted to try, and RGB Led, because why not. For few hours here’s my rainbow-ish project result.

wires

unicorn_circuits

code

#include <CapacitiveSensor.h>

int redPin = 11;
int greenPin = 10;
int bluePin = 9;

int sendPin = 4;
int RreceivePin = 2;
int GreceivePin = 6;
int BreceivePin = 8;

CapacitiveSensor   cs_4_2 = CapacitiveSensor(4,2);
CapacitiveSensor   cs_4_6 = CapacitiveSensor(4,6);
CapacitiveSensor   cs_4_8 = CapacitiveSensor(4,8);

void setup()
{
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);

  Serial.begin(9600);
}

void loop()
{
  long start = millis();
  long total1 =  cs_4_2.capacitiveSensor(30);
  long total2 =  cs_4_6.capacitiveSensor(30);
  long total3 =  cs_4_8.capacitiveSensor(30);

  Serial.print(millis() - start);       
  Serial.print("t");                   
  Serial.print(total1);                 
  Serial.print("t");
  Serial.print(total2);
  Serial.print("t");
  Serial.println(total3);

  int colorR = (int)map(total1, 0, 100, 0, 255);
  int colorG = (int)map(total2, 0, 100, 0, 255);
  int colorB = (int)map(total3, 0, 100, 0, 255);

  setColor(colorR, colorG, colorB);

  delay(50);
}

void setColor(int red, int green, int blue)
{
  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue);  
}

references: 1, 2

Leave a Comment.