Dot Matrix Drawing
Use the Joystick to move a dot on the MAX7219 LED Dot Matrix
Components and supplies
16
Male/Male Jumper Wires
1
Analog joystick (Generic)
10
Male/Female Jumper Wires
1
Rotary Potentiometer, 10 kohm
1
Arduino UNO
1
Standard LCD - 16x2 White on Blue
Apps and platforms
1
Arduino IDE
Project description
Code
MAX7219_joystick.ino
arduino
1 2 3//We always have to include the library 4#include "LedControl.h" 5#include <LiquidCrystal.h> 6/* 7 Now we need a LedControl to work with. 8 ***** These pin numbers will probably not work with your hardware ***** 9 pin 12 is connected to the DataIn 10 pin 11 is connected to LOAD(CS) 11 pin 10 is connected to the CLK 12 We have only a single MAX72XX. 13 */ 14LedControl lc=LedControl(4,5,6,1); 15 16// initialize the library with the numbers of the interface pins 17LiquidCrystal lcd(7, 8, 9, 10, 11, 12); 18 19/* we always wait a bit between updates of the display */ 20unsigned long delaytime1=500; 21unsigned long delaytime2=50; 22 23boolean pixels[8][8]; 24 25 26const int SW_pin = 2; // digital pin connected to switch output 27const int X_pin = 0; // analog pin connected to X output 28const int Y_pin = 1; // analog pin connected to Y output 29 30 31int row = 4; 32int column = 4; 33boolean cursorFlickerStatus = true; 34 35 36void setup() { 37 38 // set up the LCD's number of columns and rows: 39 lcd.begin(16, 2); 40 /* 41 The MAX72XX is in power-saving mode on startup, 42 we have to do a wakeup call 43 */ 44 lc.shutdown(0,false); 45 /* Set the brightness to a medium values */ 46 lc.setIntensity(0,0); 47 /* and clear the display */ 48 lc.clearDisplay(0); 49 50 /* setup joystic */ 51 pinMode(SW_pin, INPUT); 52 digitalWrite(SW_pin, HIGH); 53 Serial.begin(9600); 54 55 for(int i=0; i < 8; i++) 56 for(int l=0; l < 8; l++) 57 { 58 pixels [i][l] = false; 59 } 60} 61 62 63void updateLED() 64{ 65 lc.setLed(0,column,row,cursorFlickerStatus); 66 67 for(int i=0; i < 8; i++) 68 for(int l=0; l < 8; l++) 69 { 70 lc.setLed(0,l,i,pixels[i][l]); 71 } 72} 73 74void loop() 75{ 76 77 lcd.setCursor(0, 1); 78 79 String output = ""; 80 output+= "x:"; 81 output+= column; 82 output+= " y:"; 83 output+= row; 84 85 lcd.print(output); 86 87 88 cursorFlickerStatus = !cursorFlickerStatus; 89 90 91 if(digitalRead(SW_pin) == 0) 92 { 93 94 pixels[row][column] = !pixels[row][column]; 95 updateLED(); 96 delay(1000); 97 } 98 99 100 if(analogRead(X_pin) < 512 -100 ) 101 { 102 103 lc.setLed(0,column,row,false); 104 105 row = row -1; 106 if(row < 0) 107 row = 0; 108 109 updateLED(); 110 delay(100); 111 } 112 else if(analogRead(X_pin) > 512 +100 ) 113 { 114 lc.setLed(0,column,row,false); 115 116 row = row +1; 117 if(row > 7) 118 row = 7; 119 120 updateLED(); 121 delay(100); 122 } 123 124 if(analogRead(Y_pin) < 512 -100 ) 125 { 126 127 lc.setLed(0,column,row,false); 128 129 column = column -1; 130 if(column < 0) 131 column = 0; 132 133 updateLED(); 134 delay(100); 135 } 136 else if(analogRead(Y_pin) > 512 +100 ) 137 { 138 lc.setLed(0,column,row,false); 139 140 column = column +1; 141 if(column > 7) 142 column = 7; 143 144 updateLED(); 145 delay(100); 146 } 147 148 updateLED(); 149 150} 151
Comments
Only logged in users can leave comments