Changes for page Front I/O

Last modified by Kevin Wiki on 2024/07/07 22:48

From version 8.2
edited by Kevin Wiki
on 2024/07/05 14:00
Change comment: There is no comment for this version
To version 8.3
edited by Kevin Wiki
on 2024/07/06 11:12
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -277,7 +277,164 @@
277 277  There are 4 words, each containing 7 data bits. They do not
278 278  
279 279  
280 += Controlling center LED columns =
281 +
282 +There are a total of 4 banks of addressable LED's 12 each of the total 48.
283 +
284 +|=Register Banks|=LEDs|=Count
285 +|=Bank 1|1 2 4 6 8 10 12|7
286 +|=Bank 2|3 5 7 9 11 13|6
287 +|=Bank 3|14 16 18 20 22 23 24|7
288 +|=Bank 4|15 17 19 21|4
289 +
290 +Script for writing all permutations to display:
291 +
292 +{{code language="c++"}}
293 +#include "Wire.h" // enable I2C bus
294 +
295 +byte saa1064 = 0x3B; // define the I2C bus address for our SAA1064 (pin 1 to GND) ****
296 +
297 +void setup()
298 +{
299 + Wire.begin(); // start up I2C bus
300 +}
301 +
302 +void write(int value) {
303 + Wire.beginTransmission(saa1064);
304 + Wire.write(1);
305 +
306 + Wire.write(value);
307 + Wire.write(value);
308 + Wire.write(value);
309 + Wire.write(value);
310 +
311 + Wire.endTransmission();
312 +}
313 +
314 +void loop() {
315 + for (int value = 0; value < 127; value++) {
316 + write(value);
317 + delay(300);
318 + }
319 +}
320 +{{/code}}
321 +
322 +Since LED positions don't map sequentially with LED number we can't address them in 10-base form, but we can define each LED in binary and use OR operator to display LEDs we want.
323 +
324 +{{code language="c++"}}
325 +#include "Wire.h" // enable I2C bus
326 +
327 +#define TCAADDR 0x70
328 +byte saa1064 = 0x3B; // define the I2C bus address for our SAA1064
329 +
330 +byte bank1;
331 +byte bank2;
332 +byte bank3;
333 +byte bank4;
334 +
335 +byte activityLED = 0b00000001;
336 +byte leds[23][4] = {
337 + {0b00000010, 0b00000000, 0b00000000, 0b00000000}, // 1
338 + {0b00000000, 0b00000010, 0b00000000, 0b00000000}, // 2
339 + {0b00000100, 0b00000000, 0b00000000, 0b00000000}, // 3
340 + {0b00000000, 0b00000100, 0b00000000, 0b00000000}, // 4
341 + {0b00001000, 0b00000000, 0b00000000, 0b00000000}, // 5
342 + {0b00000000, 0b00001000, 0b00000000, 0b00000000}, // 6
343 + {0b00010000, 0b00000000, 0b00000000, 0b00000000}, // 7
344 + {0b00000000, 0b00010000, 0b00000000, 0b00000000}, // 8
345 + {0b00100000, 0b00000000, 0b00000000, 0b00000000}, // 9
346 + {0b00000000, 0b00100000, 0b00000000, 0b00000000}, // 10
347 + {0b01000000, 0b00000000, 0b00000000, 0b00000000}, // 11
348 + {0b00000000, 0b01000000, 0b00000000, 0b00000000}, // 12
349 + {0b00000000, 0b00000000, 0b00000001, 0b00000000}, // 13
350 + {0b00000000, 0b00000000, 0b00000000, 0b00000001}, // 14
351 + {0b00000000, 0b00000000, 0b00000010, 0b00000000}, // 15
352 + {0b00000000, 0b00000000, 0b00000000, 0b00000010}, // 16
353 + {0b00000000, 0b00000000, 0b00000100, 0b00000000}, // 17
354 + {0b00000000, 0b00000000, 0b00000000, 0b00000100}, // 18
355 + {0b00000000, 0b00000000, 0b00001000, 0b00000000}, // 19
356 + {0b00000000, 0b00000000, 0b00000000, 0b00001000}, // 20
357 + {0b00000000, 0b00000000, 0b00010000, 0b00000000}, // 21
358 + {0b00000000, 0b00000000, 0b00100000, 0b00000000}, // 22
359 + {0b00000000, 0b00000000, 0b01000000, 0b00000000} // 23
360 +};
361 +
362 +void setup()
363 +{
364 + Serial.begin(9600);
365 + Wire.begin(); // start up I2C bus
366 +
367 + Serial.println("setting up ports");
368 +}
369 +
370 +void tcaselect(uint8_t i) {
371 + if (i > 7) return;
280 280  
373 + Wire.beginTransmission(TCAADDR);
374 + Wire.write(1 << i);
375 + Wire.endTransmission();
376 +}
377 +
378 +void selectLeft() { tcaselect(2); }
379 +void selectRight() { tcaselect(1); }
380 +
381 +void write() {
382 + Wire.beginTransmission(saa1064);
383 + Wire.write(1);
384 +
385 + Wire.write(bank1);
386 + Wire.write(bank2);
387 + Wire.write(bank3);
388 + Wire.write(bank4);
389 +
390 + Wire.endTransmission();
391 +}
392 +
393 +void resetBanks() {
394 + bank1 = 0;
395 + bank2 = 0;
396 + bank3 = 0;
397 + bank4 = 0;
398 +}
399 +
400 +void displayNumber(int number) {
401 + bank1 = leds[number - 1][0];
402 + bank2 = leds[number - 1][1];
403 + bank3 = leds[number - 1][2];
404 + bank4 = leds[number - 1][3];
405 +}
406 +
407 +void displayUpToNumber(int number) {
408 + for (int i = 0; i < number; i++) {
409 + bank1 = bank1 | leds[i][0];
410 + bank2 = bank2 | leds[i][1];
411 + bank3 = bank3 | leds[i][2];
412 + bank4 = bank4 | leds[i][3];
413 + }
414 +}
415 +
416 +void computeEthernetActivity() {
417 + bank1 = bank1 | activityLED;
418 +}
419 +
420 +void loop() {
421 + resetBanks();
422 + delay(10);
423 +
424 + displayUpToNumber(15);
425 + computeEthernetActivity();
426 +
427 + selectLeft();
428 + write();
429 + delay(2);
430 +
431 + selectRight();
432 + write();
433 + delay(1000);
434 +}
435 +{{/code}}
436 +
437 +
281 281  )))
282 282  
283 283