2010年7月13日火曜日

Program for my artwork Ver 0.1 (unckecked)

/*
Program for Art Work
Version 0.1
Huge 7 segment controller with Shift registor.
Made by Shotaro N 2010
*/

//reguler variable
int c;
int rec1, rec2, rec3, rec4;
// error checker
int checkND=0;
//controller variables
int vTime=500;
int amount7S =4;
//Shift Registor
int latchPin = 8;
int clockPin = 12;
int dataPin = 11;


void setup()
{
Serial.begin(9600);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop(){
if(Serial.available()>0){
//reading validity of words
block1();
block2();
block3();
block4();
//to ignore words with EXtra
EXchecker();
//main checking process
if (checkND ==amount7S){
//main LED
digitalWrite(latchPin, LOW);
c = rec1;
process();
c = rec2;
process();
c = rec3;
process();
c = rec4;
process();
digitalWrite(latchPin, HIGH);
delay(vTime);
}
}//main if end
//protection reset
checkND = 0;
}

//EDN OF VOID LOOP


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

// 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, 104);
}
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);
}
}

// 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
}
}
}

0 件のコメント:

コメントを投稿