Arduino Alarm Lab CTY SAR FCPS SHAWN LUPOLI

Arduino Alarm Lab CTY SAR FCPS SHAWN LUPOLI, BENEDICT HO

What are we working with?

How to display things!!! We are using a LED Matrix Kit made by Link Sprite. We can use the LED display to show messages.

Arduino LED Matrix Schematic

Goal To be able to make a the LED display change when using the potentiometers.

Programming the LED MATRIX

Code Explanation WARNING: THERE WILL BE A LOT OF TRIAL AND ERROR. Simply explained, we make LEDs on the matrix light up by making a row HIGH or LOW, and then making a column the opposite. The place where they meet will light up on the matrix.

CODE: Creds to Arduino Website // 2 -dimensional array of row pin numbers: const int row[8] = { 2, 7, 19, 5, 13, 18, 12, 16 }; // 2 -dimensional array of column pin numbers: const int col[8] = { 6, 11, 10, 3, 17, 4, 8, 9 }; // 2 -dimensional array of pixels: int pixels[8][8]; // cursor position: int x = 5; int y = 5; void setup() { // initialize the I/O pins as outputs // iterate over the pins: for (int this. Pin = 0; this. Pin < 8; this. Pin++) { // initialize the output pins: pin. Mode(col[this. Pin], OUTPUT); pin. Mode(row[this. Pin], OUTPUT); // take the col pins (i. e. the cathodes) high to ensure that // the LEDS are off: digital. Write(col[this. Pin], HIGH); } // initialize the pixel matrix: for (int x = 0; x < 8; x++) { for (int y = 0; y < 8; y++) { pixels[x][y] = HIGH; } } } void loop() { // read input: read. Sensors(); // draw the screen: refresh. Screen(); } void read. Sensors() { // turn off the last position: pixels[x][y] = HIGH; // read the sensors for X and Y values: x = 7 - map(analog. Read(A 0), 0, 1023, 0, 7); y = map(analog. Read(A 1), 0, 1023, 0, 7); // set the new pixel position low so that the LED will turn on // in the next screen refresh: pixels[x][y] = LOW; } void refresh. Screen() { // iterate over the rows (anodes): for (int this. Row = 0; this. Row < 8; this. Row++) { // take the row pin (anode) high: digital. Write(row[this. Row], HIGH); // iterate over the cols (cathodes): for (int this. Col = 0; this. Col < 8; this. Col++) { // get the state of the current pixel; int this. Pixel = pixels[this. Row][this. Col]; // when the row is HIGH and the col is LOW, // the LED where they meet turns on: digital. Write(col[this. Col], this. Pixel); // turn the pixel off: if (this. Pixel == LOW) { digital. Write(col[this. Col], HIGH); } } // take the row pin low to turn off the whole row: digital. Write(row[this. Row], LOW); } }

Building the LED MATRIX

Supplies Arduino Board * Notes: (1) LED Matrix Kit v Wires are 22 or 24 AWG, solid v (2) potentiometers Short wires = 5 cm v Medium wires = 12 cm hook-up wire v Long wires = 16 cm breadboard

Diagram of LED MATRIX

Bibliography Arduino. "Arduino - Row. Column. Scanning. " Arduino Row. Column. Scanning. N. p. , n. d. Web. 14 July 2015. Technologies, Inc Linksprite. 2770157 LED Matrix Kit User Guide (n. d. ): n. pag. Amazon. Web. June-July 2015. <https: //s 3. amazonaws. com/linksprite/Arduino_kits/LEDmatrixkit/LED_Mart ix_Kit_User_Guide_V 2. pdf>.

Questions?
- Slides: 13