Controlling multiplexed LED's
in
Integration and Hardware
•
1 year ago
Hi all, I found
this example of multiplexing. The LED's are manipulated via Processing by moving the mouse around. I would like to be able to manipulate the LED's (i.e.) turn them ON/OF using 16 push- button switches. What to I have to add to the arduino sktech to handle the processing of physical switches.
Processing code:
- import processing.serial.*;
- Serial myPort;
- int numChannels = 16;
- void setup() {
- size(1280,800);
- // println(Serial.list());
- myPort = new Serial(this, Serial.list()[0], 9600);
- background(0);
- }
- void draw() {
- }
- void mouseMoved() {
- int ID = int(map(mouseX,0,width,0,numChannels));
- myPort.write(ID);
- }
- Arduino code:
- // 16 channels
- int r0 = 0;
- int r1 = 0;
- int r2 = 0;
- int r3 = 0;
- int row = 0;
- int ID = 0;
- int bin [] = {0, 1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111};
- void setup(){
- pinMode(2, OUTPUT);
- pinMode(3, OUTPUT);
- pinMode(4, OUTPUT);
- pinMode(5, OUTPUT);
- Serial.begin(115200);
- }
- void loop () {
- if (Serial.available()) {
- ID = Serial.read();
- Serial.print(ID);
- }
- row = bin[ID];
- r0 = row & 0x01;
- r1 = (row>>1) & 0x01;
- r2 = (row>>2) & 0x01;
- r3 = (ID>7)? 1:0;
- digitalWrite(2, r0);
- digitalWrite(3, r1);
- digitalWrite(4, r2);
- digitalWrite(5, r3);
- }
1