Thursday, September 24, 2015

Arduino Joystick with Led Matrix Display

How to setup a Led Matrix Display on an Arduino controlled by a joystick:
by J.B. Wylzan

Project 33:  Joystick controls a Led Matrix Display

This project challenges the maker to incorporate a motion detector sensor,
a speaker, and a joystick that controls a led matrix display.








Hardware:
1 PIR Motion Sensor
1 Led (indicator)
1 joystick
1 speaker
1 Led Matrix Display
connecting wires
breadboard
Arduino R3 UNO board


Connection Pins:

 DataPin, din = 12;
 LatchPin, cs  = 10;
 ClockPin, clk = 11;
 Speaker= 4;               
 Led = 13;                
 Motion Sensor, S = 5;
 Joystick x,y = A0, A1;
 Vcc, +   = 5V;
 Gnd, -   = ground;

  

Sample Sketch for PIR and Matrix Display :

/*
  iHacklab Led Matrix Display controlled by a joystick
  This sketch does the following procedures:
1. Buzzer when motion is detected
2. Display graphix when there is no motion detected.
3. Joystick controls an led in a matrix display
4. Circuit connections embedded 
 */

#include "LedControl.h"

int DataPin = 12;
int LatchPin = 10;
int ClockPin = 11;
LedControl lc=LedControl(12,11,10,1);
int spkr = 4;               
int led = 13;                
int sensor = 5;             
int state = LOW;            
int val = 0;                 
int pos = 0;
int  var = 0;


void setup() {
  pinMode(led, OUTPUT);      // initalize LED as an output
 pinMode(spkr, OUTPUT);      // initalize speaker as an output
  pinMode(sensor, INPUT);    // initialize sensor as an input
 
  lc.shutdown(0, false);
  lc.setIntensity(0, 5);
  lc.clearDisplay(0);

  delayMicroseconds(30);
}

void loop(){
  val = digitalRead(sensor);   // read sensor value
  if (val == HIGH) {           // check if the sensor is HIGH
    Serial.println("Motion detected!");
 while(var < 5) {       
        digitalWrite(13, HIGH);
        delay(1000);
       digitalWrite(13, LOW);
       delay(1000);
       tone(4, 440, 200);
      var++;
       }
   var=0;
  
    if (state == LOW) {
      digitalWrite(led, HIGH);   // turn LED ON
      state = HIGH;       // update variable state to HIGH
    }
  }
  else {
      digitalWrite(led, LOW); // turn LED OFF
      delay(200);             // delay 200 milliseconds
      rain();
    //  block();
      if (state == HIGH){
        Serial.println("Motion stopped!");
        state = LOW;       // update variable state to LOW
        
    }
  }
}


void rain()
  {
  for (int row=0; row<8; row++)
  {
    for (int col=0; col<8; col++)
    {
      lc.setLed(0,col,row,true); // turns on LED at col, row
      delay(100);
    lc.setLed(0,col,row,false); // turns on LED at col, row
    }
  }
  }

void block(){
    for (int row=0; row<8; row++)
  {
    for (int col=7; col<8; col++)
    {
      lc.setLed(0,col,row,true); // turns on LED at col, row
      delay(100);
      digitalWrite(4, LOW);
     
    }
  }
 }

  
Sample sketch for Joystick/Matrix:


#include "LedControl.h"
int A0 = 0;  //x
int A1 = 1;  //y
int Zkey = 3;    //z

LedControl lc=LedControl(12,11,10,1);


void setup() {
  Serial.begin(9600);
  pinMode(z,input);
  lc.shutdown(0,false);
  lc.setIntensity(0,5);
  lc.clearDisplay(0);

}

void loop() {
INT X,Y,Z 
  X= analogRead(A0);
  Y= analogRead(A1);
  Z =digitalRead(Zkey)
  char x = map(X, 1021, 0, 0, 7);
  char y = map(Y, 1021, 0, 7, 0);
 

  Serial.print(X, DEC);
  Serial.print(",");
  Serial.print(Y, DEC);
  Serial.print(",");
  Serial.print(Z, DEC);

    lc.clearDisplay(0);
    lc.setLed(0,x,y,true); 
    delay(100);
}





Disclaimer:  We shall not be liable for any loss or damage of whatever nature - direct, indirect, consequential, or otherwise - which may arise as a result of your use of any information on this website. However, if you are interested in using any of the projects for personal or educational purposes, please inform the author by email. 

Public Domain Notice: Copyright (c) 2000. All rights reserved. This article is part of a book entitled iHackRobot. Copies are welcome to be shared or distributed publicly as long proper citations are observed. Please cite as follows: Biotronics: The Silver Species, Joey Lawsin, 1988, USA.

================================================================== 
The Homotronics® and Homodruinos® logos are registered trademarks.
Copyright Biotronics© Inc. iHackRobot®. All Rights Reserved.
Patent Pending. 2000 © ®

L.A.W.S.I.N. Educational Production
 ================================================================== 



No comments:

Post a Comment