2010年8月17日火曜日

Technical detail of my artwork


Arduino 1

/*
Name of Arduino COM4
Program for Art Work
Version 1.4
Huge 7 segment controller with Shift registor.
Made by Shotaro N 2010

note:
Somehow,you need Serial.print(); in a function of block();.
It does not do anything, but without having it, the program does not work properly.
Ver 1.1 added relay control and LEDcontrol
Ver 1.2 fixed a relay proglem
Ver 1.3 added a daisy chain pulse controller
Ver 1.4 change daisy chain controller from transistor to relay
*/

//reguler variable to store data
int c;
int rec1, rec2, rec3, rec4;
// error checking counter
int checkND=0;
//controller variables
long vTime=45000;
int amount7S =4;
//Shift Registor
int latchPin = 8;
int clockPin = 12;
int dataPin = 11;
int latchPin2 = 2;
int clockPin2 = 4;
int dataPin2 = 3;
int ledPin =13;
int relayPin =6;
int daisyChainPin = 7;

void setup()
{
Serial.begin(9600);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(latchPin2, OUTPUT);
pinMode(clockPin2, OUTPUT);
pinMode(dataPin2, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(relayPin, OUTPUT);
pinMode(daisyChainPin, OUTPUT);
digitalWrite(daisyChainPin, LOW);
delay(10);
digitalWrite(relayPin, LOW);
delay(10);
}

void loop(){
digitalWrite(relayPin, HIGH);
delay(10);
if(Serial.available()>0){
//reading validity of words
block1();
block2();
block3();
block4();
Serial.println("");
Serial.print("CheckND value");
Serial.println(checkND);
//to ignore words with EXtra
EXchecker();
Serial.print("CheckND value");
Serial.println(checkND);
//main checking process
if (checkND ==amount7S){
Serial.println("start light LEDs section");
digitalWrite(relayPin, LOW);
digitalWrite(daisyChainPin, HIGH);
delay(1);
Serial.print("Sending a pulse to the second Arduino");
Serial.print(".");
Serial.print(".");
Serial.println(".");
digitalWrite(ledPin, HIGH);
//main LED
digitalWrite(latchPin, LOW);
c = rec4;
process();
c = rec3;
process();
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin2, LOW);
c = rec2;
processSEC();
c = rec1;
processSEC();
digitalWrite(latchPin2, HIGH);
delay(vTime);
checkND = 0;
reset();
digitalWrite(ledPin, LOW);
digitalWrite(daisyChainPin, LOW);
digitalWrite(relayPin, HIGH);
delay(1);
}
//checkND = 0;
//reset();
}//main if end
//protection reset
checkND = 0;
reset();
}

//EDN OF VOID LOOP


//first block
void block1(){
rec1=Serial.read();
c = rec1;
Cprocess();//check prosecc
Serial.print("block1");
}
//second block
void block2(){
rec2=Serial.read();
c = rec2;
Cprocess();
Serial.print("block2");
}
//third block
void block3(){
rec3=Serial.read();
c = rec3;
Cprocess();
Serial.print("block3");
}
//Fourth block
void block4(){
rec4=Serial.read();
c = rec4;
Cprocess();
Serial.print("block4");
}

// checker
void Cprocess(){
if(c=='8'){
checkND = checkND + 1;
}
else if(c=='0'){
checkND = checkND + 1;
}
else if(c=='1'){
checkND = checkND + 1;
}
else if(c=='2'){
checkND = checkND + 1;
}
else if(c=='3'){
checkND = checkND + 1;
}
else if(c=='4'){
checkND = checkND + 1;
}
else if(c=='5'){
checkND = checkND + 1;
}
else if(c=='6'){
checkND = checkND + 1;
}
else if(c=='7'){
checkND = checkND + 1;
}
else if(c=='9'){
checkND = checkND + 1;
}
else{
}
}

//judgement & lighting
void process(){
if(c=='8'){
shiftOut(dataPin, clockPin, MSBFIRST, 254);
}
else if(c=='0'){
shiftOut(dataPin, clockPin, MSBFIRST, 250);
}
else if(c=='1'){
shiftOut(dataPin, clockPin, MSBFIRST, 96);
}
else if(c=='2'){
shiftOut(dataPin, clockPin, MSBFIRST, 220);
}
else if(c=='3'){
shiftOut(dataPin, clockPin, MSBFIRST, 244);
}
else if(c=='4'){
shiftOut(dataPin, clockPin, MSBFIRST, 102);
}
else if(c=='5'){
shiftOut(dataPin, clockPin, MSBFIRST, 182);
}
else if(c=='6'){
shiftOut(dataPin, clockPin, MSBFIRST, 62);
}
else if(c=='7'){
shiftOut(dataPin, clockPin, MSBFIRST, 226);
}
else if(c=='9'){
shiftOut(dataPin, clockPin, MSBFIRST, 230);
}
}

//judgement & lighting
void processSEC(){
if(c=='8'){
shiftOut(dataPin2, clockPin2, MSBFIRST, 254);
}
else if(c=='0'){
shiftOut(dataPin2, clockPin2, MSBFIRST, 250);
}
else if(c=='1'){
shiftOut(dataPin2, clockPin2, MSBFIRST, 96);
}
else if(c=='2'){
shiftOut(dataPin2, clockPin2, MSBFIRST, 220);
}
else if(c=='3'){
shiftOut(dataPin2, clockPin2, MSBFIRST, 244);
}
else if(c=='4'){
shiftOut(dataPin2, clockPin2, MSBFIRST, 102);
}
else if(c=='5'){
shiftOut(dataPin2, clockPin2, MSBFIRST, 182);
}
else if(c=='6'){
shiftOut(dataPin2, clockPin2, MSBFIRST, 62);
}
else if(c=='7'){
shiftOut(dataPin2, clockPin2, MSBFIRST, 226);
}
else if(c=='9'){
shiftOut(dataPin2, clockPin2, MSBFIRST, 230);
}
}


// EXchecker. protect system from invalid value
void EXchecker(){
if(Serial.available()>0){
int reader = Serial.read();
if(reader == -1){
}
else{
checkND = checkND +10;// protect from hack
}
}
}


void reset(){
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 0);
shiftOut(dataPin, clockPin, MSBFIRST, 0);
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin2, LOW);
shiftOut(dataPin2, clockPin2, MSBFIRST, 0);
shiftOut(dataPin2, clockPin2, MSBFIRST, 0);
digitalWrite(latchPin2, HIGH);
}




Arduino 2

  


/*
Program for second Arduino
Ver 1.3

Serial in Watcher "1" got data from daisy chain
Serial in Watcher "2" got data from ultrasonic range finder
Serial in Watcher "3" got data from motion sensor

Ver 1.0 basic
Ver 1.1 error correction about values
added while loop to fix communication Arduino and Isadora
Ver 1.2 fixed motion sensor value
Ver 1.3 fixed problem especially reset commend
Ver 1.4 take out motion sensor and reduce pressure to a computer
*/

//regular variable
//int alarmValue = 1;
int val=0;
int defaultLength=330; // max value of sonic range finder

//analog pins
//int alarmPin = 1;//motion sensor
int daisyChainPin = 0;
//digital pins
int ledPin = 13;
const int pingPin = 7;//Ultrasonic

//loop speed
int delayTime = 200;


void setup () {
Serial.begin (9600);
pinMode(ledPin, OUTPUT);
//pinMode(alarmPin, INPUT);
//delay (2000); //wait for a motion sensor to be ready to go
digitalWrite(ledPin, LOW);
}

void loop ()
{
val = analogRead(daisyChainPin);
if (val>100){

//turn on LED while the second arduino got pulse from the first arduino
digitalWrite(ledPin, HIGH);


val =1;//to activate Isadora
Serial.print(1,DEC);
Serial.print (val, DEC);
Serial.println();
val = analogRead(daisyChainPin);
while(val>100){
/*
for ultrasonic range finder. source from
http://www.arduino.cc/en/Tutorial/Ping

created 3 Nov 2008
by David A. Mellis
modified 30 Jun 2009
by Tom Igoe
*/

long duration, cm;
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
cm = microsecondsToCentimeters(duration);

//ignore crazy value

if(cm>330){
cm = 330;
}

//send this value to use for something

Serial.print(2,DEC);
Serial.print (cm, DEC);
Serial.println();


//motion sensor
//based on http://www.eathertons.com/blog/?p=73
//Shotaro fixed the code little bit
/*
alarmValue = analogRead(alarmPin);
if (alarmValue < 100){
alarmValue =1;
sendPulse();
}
else{
}
*/
delay(delayTime);

val = analogRead(daisyChainPin);//Value for While
}//While loop
digitalWrite(ledPin, LOW);
dataReset();
}
}
//END of void loop




//culculation from microsecond to length
long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}



/*
//send a data from motion sensor to Isadora
//This value will control "counter" of Isadora
void sendPulse() {
Serial.print(3,DEC);
Serial.print (alarmValue, DEC);
Serial.println();
}
*/

void dataReset(){
Serial.print(1,DEC);
Serial.print (0, DEC);
Serial.println();
Serial.print(2,DEC);
Serial.print (defaultLength, DEC);
Serial.println();
//Serial.print(3,DEC);
//Serial.print (0, DEC);
//Serial.println();
}



Arduino 3



int alarmPin = 1;//motion sensor
int alarmValue = 1;
int delayTime = 200;


void setup(){
Serial.begin(9600);
pinMode(alarmPin, INPUT);
delay (2000); //wait for a motion sensor to be ready to go
}
void loop(){
alarmValue = analogRead(alarmPin);
if (alarmValue < 100){
//alarmValue =1;
sendPulse();
}
else{
}
delay(delayTime);
}

//send a data from motion sensor to Isadora
//This value will control "counter" of Isadora
void sendPulse() {
Serial.print(3,DEC);
Serial.print (alarmValue, DEC);
Serial.println();
}

0 件のコメント:

コメントを投稿