2012年12月3日 星期一

2012年11月17日 星期六

2012年10月3日 星期三

4模式的廣告燈

Sample TestSubroutine  https://www.dropbox.com/sh/v5ubv00b6vdl3hg/GHNAlyAoGj


#define SW0 2
#define SW1 3
#define LED0 4
#define LED1 5
#define LED2 6
#define LED3 7
#define LED4 8
#define LED5 9
#define LED6 10
#define LED7 11
void setup() {
  Serial.begin(9600);
  Serial.println("Chang Yung Fu <<<2012/10/4>>>");
  Serial.println("4 Mode Led Flash using  Arduino");
  pinMode(SW0,INPUT);  pinMode(SW1,INPUT);
  for (int i=0;i<=7;i++) pinMode(4+i,OUTPUT);
 }
void loop() {
  int Mode;
  char OutData;
  //4模式的表格宣告
  char Mode1[]={1,2,4,8,16,32,64,128};
  char Mode2[]={0x81,0x42,0x24,0x18,0x24,0x42};
  char Mode3[]={0xF0,0x0F};
  //Input Map to Var
  Mode=digitalRead(SW0) | (digitalRead(SW1)<<1);
  Serial.print("MODE=");Serial.println(Mode);
  switch (Mode)
     {case 0:.....;break;
       case 1:.....;break;
      case 2:......;break;
      case 3:......;break;  
     }

  //Var Map to Output
  delay(100);
}
int SN7490(boolean UP_DN,int MAX)
{
  int static i=0;
  if (UP_DN) {
    i++;
    if (i>MAX) i=0;
  }
  else {
    i--;
      if (i<0) i=MAX;
  }
  return i;
}


2012年9月19日 星期三

Arduino::Boolean AND Gate



//boolean_and.pde
#define A 2
#define B 3
#define Y0 4

void setup() {
Serial.begin(9600);
Serial.println("Chang Yung Fu <<<2012/9/20>>>");
Serial.println("Combining Logic using  Arduino");
Serial.println("Boolean algebra AND Gate example");
Serial.println("Y0=B*A");
Serial.println("B,A=>Y0");
Serial.println("------------");
Serial.println("0,0  =>0");
Serial.println("0,1  =>0");
Serial.println("1,0  =>0");
Serial.println("1,1  =>1");

pinMode(A,INPUT);
pinMode(B,INPUT);
pinMode(Y0,OUTPUT);
}
void loop() {
boolean OutY0;
OutY0=digitalRead(B) && digitalRead(A) ;
digitalWrite(Y0,OutY0);
}

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);
}

Arduino::Simulate IC 7483



#define A_0 2
#define A_1 3
#define A_2 4
#define A_3 5
#define B_0 6
#define B_1 7
#define B_2 8
#define B_3 9
#define S0 10
#define S1 11
#define S2 12
#define S3 13
#define S4 14
void setup() {
Serial.begin(9600);
Serial.println("Chang Yung Fu <<<2012/9/18>>>");
Serial.println("Combining Logic using  Arduino");
Serial.println("Simulate IC7483");
Serial.println("S[4..0]=A[3..0]+B[3..0]");
pinMode(A_0,INPUT);
pinMode(A_1,INPUT);
pinMode(A_2,INPUT);
pinMode(A_3,INPUT);
pinMode(B_0,INPUT);
pinMode(B_1,INPUT);
pinMode(B_2,INPUT);
pinMode(B_3,INPUT);
pinMode(S0,OUTPUT);
pinMode(S1,OUTPUT);
pinMode(S2,OUTPUT);
pinMode(S3,OUTPUT);
pinMode(S4,OUTPUT);
}
void loop() {
int Ain,Bin,Sum;
int InA,InB,InC,InD;

//Input Pin Map InData
InA=digitalRead(A_0);
InB=digitalRead(A_1);
InC=digitalRead(A_2);
InD=digitalRead(A_3);
//Input Pin Map Ain
Ain=(InA) | (InB<<1) | (InC<<2) | (InD<<3);
//Input Pin Map Bin
InA=digitalRead(B_0);
InB=digitalRead(B_1);
InC=digitalRead(B_2);
InD=digitalRead(B_3);
Bin=(InA) | (InB<<1) | (InC<<2) | (InD<<3);
Sum=Ain+Bin;
//Serial.print("Ain=0x");Serial.println(Ain,HEX);
//Serial.print("Bin=0x");Serial.println(Bin,HEX);
//Serial.print("Sum=0x");Serial.println(Sum,HEX);
//Serial.println("===========================");
//Sum Map Output Pin
if ((Sum & 1)!=0) //-------------check bit 0
    {digitalWrite(S0,HIGH);}
else
    {digitalWrite(S0,LOW);}
if ((Sum & 2)!=0) //-------------check bit 1
    {digitalWrite(S1,HIGH);}
else
    {digitalWrite(S1,LOW);}
if ((Sum & 4)!=0) //-------------check bit 2
    {digitalWrite(S2,HIGH);}
else
    {digitalWrite(S2,LOW);}
if ((Sum & 8)!=0) //-------------check bit 3
    {digitalWrite(S3,HIGH);}
else
    {digitalWrite(S3,LOW);}
if ((Sum & 16)!=0) //-------------check bit 4
    {digitalWrite(S4,HIGH);}
else
    {digitalWrite(S4,LOW);}      
}