Multiplexing deel 3 (ofzo)

 ▬

int dataPin  = 5; // HC595
int latchPin = 6;
int clockPin = 7; 

int Latch  = 12; // HEF4514
int Enable = 13;
int pinA0  = 8;
int pinA1  = 9;
int pinA2  = 10;
int pinA3  = 11;

int licht;
int l;

int BB1[] = { B00000001,
B00000010, B00000100, B00001000,
B00010000, B00100000, B01000000,
B10000000, B00000000, B00000000,
B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000 };
int BB2[] = { B00000000,
B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000,
B00000000, B00000001, B00000010,
B00000100, B00001000, B00010000,
B00100000, B01000000, B10000000 };

void setup()
{
Serial.begin(9600);
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(Latch, OUTPUT);
  pinMode(Enable, OUTPUT);
  pinMode(pinA0, OUTPUT);
  pinMode(pinA1, OUTPUT);
  pinMode(pinA2, OUTPUT);
  pinMode(pinA3, OUTPUT);
  pinMode(pinA3, OUTPUT);
  digitalWrite(Enable, LOW);
}

void loop(){

for (int y =0; y<16;y++){
  licht = analogRead(A0);
      l = map(licht,900,1000,0,16);
      l = constrain(l,0,15);
  shiftIt (0xFF -BB1[l],0xFF - BB2[l]);   
  digitalWrite(Latch, HIGH);
  digitalWrite(pinA0, (y & 1));
  digitalWrite(pinA1, (y & 2));
  digitalWrite(pinA2, (y & 4));
  digitalWrite(pinA3, (y & 8));
  digitalWrite(Latch, LOW);
  }
}

void shiftIt (byte b1, byte b2){
  digitalWrite(latchPin, LOW);

  for (int k=0; k < 8; k++){
    digitalWrite(clockPin, LOW);
    if ( b1 & (1 << k) ){
      digitalWrite(dataPin, HIGH);
    }
    else{
      digitalWrite(dataPin, LOW);
    }
    digitalWrite(clockPin, HIGH);
    }
  for (int k=0; k < 8; k++){
    digitalWrite(clockPin, LOW);
    if ( b2 & (1 << k) ){
      digitalWrite(dataPin, HIGH);
    }
    else{
      digitalWrite(dataPin, LOW);
    }
    digitalWrite(clockPin, HIGH);
    }
    digitalWrite(clockPin, LOW);
    digitalWrite(latchPin, HIGH);
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>