Advertisement
metalx1000

Arduino LED 8 digit Display 8 segment serial control

Jul 9th, 2016
776
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.23 KB | None | 0 0
  1. #include "LedControl.h"
  2. String inString = "";
  3. int pos = 0;
  4. // Arduino Pin 7 to DIN, 6 to Clk, 5 to LOAD, no.of devices is 1
  5. LedControl lc = LedControl(7, 6, 5, 1);
  6. void setup() {
  7.     Serial.begin(115200);
  8.     // Initialize the MAX7219 device
  9.     lc.shutdown(0, false); // Enable display
  10.     lc.setIntensity(0, 10); // Set brightness level (0 is min, 15 is max)
  11.     lc.clearDisplay(0); // Clear display register
  12.     for (int i = 0; i < 8; i++) {
  13.         lc.setDigit(0, i, i + 1, false);
  14.     }
  15. }
  16. void loop() {
  17.  
  18.     // send data only when you receive data:
  19.     if (Serial.available() > 0) {
  20.         int inChar = Serial.read();
  21.         if (isDigit(inChar)) {
  22.             inString = (char) inChar;
  23.         }
  24.  
  25.         if (inChar == '\n') {
  26.             int x = inString.toInt();
  27.             Serial.print("I received: ");
  28.             Serial.println(x);
  29.             lc.setDigit(0, pos, x, false);
  30.             pos++;
  31.             if (pos > 7) {
  32.                 pos = 0;
  33.             }
  34.         }
  35.     }
  36. }
  37.  
  38. //To connect through Linux Shell
  39. //stty raw -echo < /dev/ttyUSB0 #activate connection
  40. //while [ 1 ];do for i in `seq 0 9`;do for x in `seq 0 9`;do echo $i > /dev/ttyUSB0;sleep .05;done;done;done #this loops through all digits
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement