初始化提交

This commit is contained in:
王立帮
2024-07-20 22:09:06 +08:00
commit c247dd07a6
6876 changed files with 2743096 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Max72xxPanel.h>
int pinCS = 10; // Attach CS to this pin, DIN to MOSI and CLK to SCK (cf http://arduino.cc/en/Reference/SPI )
int numberOfHorizontalDisplays = 1;
int numberOfVerticalDisplays = 1;
Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays);
int pinRandom = A0;
int wait = 20; // In milliseconds
void setup() {
matrix.setIntensity(4); // Set brightness between 0 and 15
// Adjust to your own needs
// matrix.setPosition(0, 0, 0); // The first display is at <0, 0>
// matrix.setPosition(1, 1, 0); // The second display is at <1, 0>
// matrix.setPosition(2, 2, 0); // The third display is at <2, 0>
// matrix.setPosition(3, 3, 0); // And the last display is at <3, 0>
// ...
// matrix.setRotation(0, 2); // The first display is position upside down
// matrix.setRotation(3, 2); // The same hold for the last display
randomSeed(analogRead(pinRandom)); // Initialize random generator
}
int x = numberOfHorizontalDisplays * 8 / 2;
int y = numberOfVerticalDisplays * 8 / 2;
int xNext, yNext;
void loop() {
matrix.drawPixel(x, y, HIGH);
matrix.write(); // Send bitmap to display
delay(wait);
matrix.drawPixel(x, y, LOW); // Erase the old position of our dot
do {
switch ( random(4) ) {
case 0: xNext = constrain(x + 1, 0, matrix.width() - 1); yNext = y; break;
case 1: xNext = constrain(x - 1, 0, matrix.width() - 1); yNext = y; break;
case 2: yNext = constrain(y + 1, 0, matrix.height() - 1); xNext = x; break;
case 3: yNext = constrain(y - 1, 0, matrix.height() - 1); xNext = x; break;
}
}
while ( x == xNext && y == yNext ); // Repeat until we find a new coordinate
x = xNext;
y = yNext;
}

View File

@@ -0,0 +1,91 @@
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Max72xxPanel.h>
int pinCS = 10; // Attach CS to this pin, DIN to MOSI and CLK to SCK (cf http://arduino.cc/en/Reference/SPI )
int numberOfHorizontalDisplays = 1;
int numberOfVerticalDisplays = 1;
Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays);
const int pinRandom = A0;
const int wait = 100; // In milliseconds
const int length = 8;
int x[length], y[length];
int ptr, nextPtr;
void setup() {
matrix.setIntensity(4); // Set brightness between 0 and 15
// Adjust to your own needs
// matrix.setPosition(0, 0, 0); // The first display is at <0, 0>
// matrix.setPosition(1, 1, 0); // The second display is at <1, 0>
// matrix.setPosition(2, 2, 0); // The third display is at <2, 0>
// matrix.setPosition(3, 3, 0); // And the last display is at <3, 0>
// ...
// matrix.setRotation(0, 2); // The first display is position upside down
// matrix.setRotation(3, 2); // The same hold for the last display
// Reset all variables
for ( ptr = 0; ptr < length; ptr++ ) {
x[ptr] = numberOfHorizontalDisplays * 8 / 2;
y[ptr] = numberOfVerticalDisplays * 8 / 2;
}
nextPtr = 0;
randomSeed(analogRead(pinRandom)); // Initialize random generator
}
void loop() {
// Shift pointer to the next segment
ptr = nextPtr;
nextPtr = next(ptr);
matrix.drawPixel(x[ptr], y[ptr], HIGH); // Draw the head of the snake
matrix.write(); // Send bitmap to display
delay(wait);
if ( ! occupied(nextPtr) ) {
matrix.drawPixel(x[nextPtr], y[nextPtr], LOW); // Remove the tail of the snake
}
for ( int attempt = 0; attempt < 10; attempt++ ) {
// Jump at random one step up, down, left, or right
switch ( random(4) ) {
case 0: x[nextPtr] = constrain(x[ptr] + 1, 0, matrix.width() - 1); y[nextPtr] = y[ptr]; break;
case 1: x[nextPtr] = constrain(x[ptr] - 1, 0, matrix.width() - 1); y[nextPtr] = y[ptr]; break;
case 2: y[nextPtr] = constrain(y[ptr] + 1, 0, matrix.height() - 1); x[nextPtr] = x[ptr]; break;
case 3: y[nextPtr] = constrain(y[ptr] - 1, 0, matrix.height() - 1); x[nextPtr] = x[ptr]; break;
}
if ( ! occupied(nextPtr) ) {
break; // The spot is empty, break out the for loop
}
}
}
boolean occupied(int ptrA) {
for ( int ptrB = 0 ; ptrB < length; ptrB++ ) {
if ( ptrA != ptrB ) {
if ( equal(ptrA, ptrB) ) {
return true;
}
}
}
return false;
}
int next(int ptr) {
return (ptr + 1) % length;
}
boolean equal(int ptrA, int ptrB) {
return x[ptrA] == x[ptrB] && y[ptrA] == y[ptrB];
}

View File

@@ -0,0 +1,46 @@
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Max72xxPanel.h>
int pinCS = 10; // Attach CS to this pin, DIN to MOSI and CLK to SCK (cf http://arduino.cc/en/Reference/SPI )
int numberOfHorizontalDisplays = 1;
int numberOfVerticalDisplays = 1;
Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays);
void setup() {
matrix.setIntensity(0);
// Adjust to your own needs
// matrix.setPosition(0, 0, 0); // The first display is at <0, 0>
// matrix.setPosition(1, 1, 0); // The second display is at <1, 0>
// matrix.setPosition(2, 2, 0); // The third display is at <2, 0>
// matrix.setPosition(3, 3, 0); // And the last display is at <3, 0>
// ...
// matrix.setRotation(0, 2); // The first display is position upside down
// matrix.setRotation(3, 2); // The same hold for the last display
}
int wait = 50;
int inc = -2;
void loop() {
for ( int x = 0; x < matrix.width() - 1; x++ ) {
matrix.fillScreen(LOW);
matrix.drawLine(x, 0, matrix.width() - 1 - x, matrix.height() - 1, HIGH);
matrix.write(); // Send bitmap to display
delay(wait);
}
for ( int y = 0; y < matrix.height() - 1; y++ ) {
matrix.fillScreen(LOW);
matrix.drawLine(matrix.width() - 1, y, 0, matrix.height() - 1 - y, HIGH);
matrix.write(); // Send bitmap to display
delay(wait);
}
wait = wait + inc;
if ( wait == 0 ) inc = 2;
if ( wait == 50 ) inc = -2;
}

View File

@@ -0,0 +1,55 @@
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Max72xxPanel.h>
int pinCS = 10; // Attach CS to this pin, DIN to MOSI and CLK to SCK (cf http://arduino.cc/en/Reference/SPI )
int numberOfHorizontalDisplays = 4;
int numberOfVerticalDisplays = 1;
Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays);
String tape = "Arduino";
int wait = 20; // In milliseconds
int spacer = 1;
int width = 5 + spacer; // The font width is 5 pixels
void setup() {
matrix.setIntensity(7); // Use a value between 0 and 15 for brightness
// Adjust to your own needs
// matrix.setPosition(0, 0, 0); // The first display is at <0, 0>
// matrix.setPosition(1, 1, 0); // The second display is at <1, 0>
// matrix.setPosition(2, 2, 0); // The third display is at <2, 0>
// matrix.setPosition(3, 3, 0); // And the last display is at <3, 0>
// ...
// matrix.setRotation(0, 2); // The first display is position upside down
// matrix.setRotation(3, 2); // The same hold for the last display
}
void loop() {
for ( int i = 0 ; i < width * tape.length() + matrix.width() - 1 - spacer; i++ ) {
matrix.fillScreen(LOW);
int letter = i / width;
int x = (matrix.width() - 1) - i % width;
int y = (matrix.height() - 8) / 2; // center the text vertically
while ( x + width - spacer >= 0 && letter >= 0 ) {
if ( letter < tape.length() ) {
matrix.drawChar(x, y, tape[letter], HIGH, LOW, 1);
}
letter--;
x -= width;
}
matrix.write(); // Send bitmap to display
delay(wait);
}
}