Pages: [1]   Go Down
Author Topic: code connections  (Read 244 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 35
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i got this code of the internet for one man pong you move the paddle left and right to hit the ball it will hit the wall and come back
it is on a 8x8 LED matrix with a max7219 but which do the clock, load and data pins go to on the arduino

Code:
#include <LedControl.h>

LedControl myMatrix = LedControl(2, 4, 3, 1);

int column = 1, row = random(8)+1;
int directionX = 1, directionY = 1;
int paddle1 = 5, paddle1Val;
int speed = 300;
int counter = 0, mult = 10;

void setup()
{
  myMatrix.shutdown(0, false);
  myMatrix.setIntensity(0, 8);
  myMatrix.clearDisplay(0);
  randomSeed(analogRead(0));
}

void loop()
{
  paddle1Val = analogRead(paddle1);
  paddle1Val = map(paddle1Val, 200, 1024, 1,6);
  column += directionX;
  row += directionY;
  if (column == 6 && directionX == 1 && (paddle1Val == row || paddle1Val+1 == row || paddle1Val+2 == row)) {directionX = -1;}
  if (column == 0 && directionX == -1 ) {directionX = 1;}
  if (row == 7 && directionY == 1 ) {directionY = -1;}
  if (row == 0 && directionY == -1 ) {directionY = 1;}
  if (column == 7) { oops();}
  myMatrix.clearDisplay(0);
  myMatrix.setLed(0, column, row, HIGH);
  myMatrix.setLed(0, 7, paddle1Val, HIGH);
  myMatrix.setLed(0, 7, paddle1Val+1, HIGH);
  myMatrix.setLed(0, 7, paddle1Val+2, HIGH);
  if (!(counter % mult)) {speed -= 5; mult * mult;}
  delay(speed);
  counter++;
}
void oops() {
  for (int x=0; x<3; x++){
    myMatrix.clearDisplay(0);
    delay(250);
    for (int y=0; y<8; y++) {
      myMatrix.setRow(0, y, 255);
    }
    delay(250);
  }
  counter=0;
  speed=300;
  column=1;
  row = random(8)+1;
}
 
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 180
Posts: 8108
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Look at LedControl.h to see what order the pins are in.

Here is a similar project: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1244503453

From that it seem like the pins are specified in the order:  Data, Clock, Load.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Pages: [1]   Go Up
Jump to: