2012年9月18日 星期二

Boolean Algebra



#define A 2
#define B 3
#define C 4
#define Y0 5
#define Y1 6
#define Y2 7
#define Y3 8
void setup() {
Serial.begin(9600);
Serial.println("Chang Yung Fu <<<2012/9/18>>>");
Serial.println("Combining Logic using  Arduino");
Serial.println("Boolean algebra example");
Serial.println("Y0=/C*/B*/A+C*B*A");
Serial.println("Y1=/C*/B*A+C*B*/A");
Serial.println("Y2=/C*B*/A+C*/B*A");
Serial.println("Y3=/C*B*A+C*/B*/A");
Serial.println("C,B,A=>Y3,Y2,Y1,Y0");
Serial.println("--------------------");
Serial.println("0,0,0  =>0,0,0,1");
Serial.println("0,0,1  =>0,0,1,0");
Serial.println("0,1,0  =>0,1,0,0");
Serial.println("0,1,1  =>1,0,0,0");
Serial.println("1,0,0  =>1,0,0,0");
Serial.println("1,0,1  =>0,1,0,0");
Serial.println("1,1,0  =>0,0,1,0");
Serial.println("1,1,1  =>0,0,0,1");

pinMode(A,INPUT);
pinMode(B,INPUT);
pinMode(C,INPUT);
pinMode(Y0,OUTPUT);
pinMode(Y1,OUTPUT);
pinMode(Y2,OUTPUT);
pinMode(Y3,OUTPUT);
}
void loop() {
  boolean OutY3,OutY2,OutY1,OutY0;
//Serial.println("Y0=/C*/B*/A+C*B*A");
OutY0=!digitalRead(C) && !digitalRead(B) && !digitalRead(A) ||digitalRead(C) && digitalRead(B) && digitalRead(A) ;
//Serial.println("Y1=/C*/B*A+C*B*/A");
OutY1=!digitalRead(C) && !digitalRead(B) && digitalRead(A) ||digitalRead(C) && digitalRead(B) && !digitalRead(A) ;
//Serial.println("Y2=/C*B*/A+C*/B*A");
OutY2=!digitalRead(C) && digitalRead(B) && !digitalRead(A) ||digitalRead(C) && !digitalRead(B) && digitalRead(A) ;
//Serial.println("Y3=/C*B*A+C*/B*/A");
OutY3=!digitalRead(C) && digitalRead(B) && digitalRead(A) ||digitalRead(C) && !digitalRead(B) && !digitalRead(A) ;
digitalWrite(Y0,OutY0);
digitalWrite(Y1,OutY1);
digitalWrite(Y2,OutY2);
digitalWrite(Y3,OutY3);
}

沒有留言:

張貼留言