Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Adafruit_NeoMatrix example for single NeoPixel Shield.
- // Scrolls 'Howdy' across the matrix in a portrait (vertical) orientation.
- #include <Adafruit_GFX.h>
- #include <Adafruit_NeoMatrix.h>
- #include <Adafruit_NeoPixel.h>
- #ifndef PSTR
- #define PSTR // Make Arduino Due happy
- #endif
- #define PIN 2
- // MATRIX DECLARATION:
- // Parameter 1 = width of NeoPixel matrix
- // Parameter 2 = height of matrix
- // Parameter 3 = pin number (most are valid)
- // Parameter 4 = matrix layout flags, add together as needed:
- // NEO_MATRIX_TOP, NEO_MATRIX_BOTTOM, NEO_MATRIX_LEFT, NEO_MATRIX_RIGHT:
- // Position of the FIRST LED in the matrix; pick two, e.g.
- // NEO_MATRIX_TOP + NEO_MATRIX_LEFT for the top-left corner.
- // NEO_MATRIX_ROWS, NEO_MATRIX_COLUMNS: LEDs are arranged in horizontal
- // rows or in vertical columns, respectively; pick one or the other.
- // NEO_MATRIX_PROGRESSIVE, NEO_MATRIX_ZIGZAG: all rows/columns proceed
- // in the same order, or alternate lines reverse direction; pick one.
- // See example below for these values in action.
- // Parameter 5 = pixel type flags, add together as needed:
- // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
- // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
- // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
- // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
- // Example for NeoPixel Shield. In this application we'd like to use it
- // as a 5x8 tall matrix, with the USB port positioned at the top of the
- // Arduino. When held that way, the first pixel is at the top right, and
- // lines are arranged in columns, progressive order. The shield uses
- // 800 KHz (v2) pixels that expect GRB color data.
- Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(45, 20, PIN,
- NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
- NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG,
- NEO_GRB + NEO_KHZ800);
- const uint16_t colors[] = {
- matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255) };
- //Matriz setup
- int width = matrix.width();
- int height = matrix.height();
- int speedx = -1;
- int speedy = 1;
- int pass = 0;
- int x=width/2;
- int y=height/2;
- int p1,p2;
- int pote1=0;
- //int =0;
- void barrita(int nump, int play){
- if (nump==1) {
- for (int i=0; i<5; i++) {
- matrix.drawPixel(0,play-1+i,0xFFFF);
- matrix.drawPixel(1,play-1+i,0xFFFF);
- }
- }
- else { for (int i=0; i<5; i++){
- matrix.drawPixel(width-1 ,play-1+i,0xFFFF);
- matrix.drawPixel(width-2 ,play-1+i,0xFFFF);
- }
- }
- }
- void setup() {
- //Matriz 1
- matrix.begin();
- matrix.setTextWrap(false);
- matrix.setBrightness(40);
- matrix.setTextColor(colors[0]);
- p1=height/2;
- p2=height/2;
- Serial.begin(9600);
- }
- void loop() {
- //Pelota
- matrix.fillScreen(0);
- x=x+speedx; y=y+speedy;
- matrix.drawPixel(x,y,0xFFFF);
- //Borde
- bool cambio=false;
- for (int i=0; i<width; i++){
- matrix.drawPixel(i, 1, 0xFFFF);
- matrix.drawPixel(i, height-1, 0xFFFF);
- if ( ( (y==p1-1) || (y==p1) || (y==p1+1) || (y==p1+2) || (y==p1+3) ) && ((x==0) || (x==width-3)) ) {
- matrix.drawPixel(x, y, 0x0000);
- }
- }
- for (int i=0; i<height; i++){
- if (cambio){
- matrix.drawPixel(width/2, i, 0xFFFF);
- cambio=false;
- }else{
- cambio=true;
- }
- }
- //Player1&2
- p1=analogRead(A0);
- p2=analogRead(A1);
- p1=map(p1,100,900,0,11)+4;
- p2=map(p2,100,900,0,10)+4;
- barrita(1,p1);
- barrita(2,p2);
- //Player 2 print
- Serial.print(p2-1);
- Serial.print('-');
- Serial.print(p2);
- Serial.print('-');
- Serial.print(p2+1);
- Serial.print('-');
- Serial.print(p2+2);
- Serial.print('-');
- Serial.print(p2+3);
- Serial.print(' ');
- //Player 1 print
- Serial.print(p1-1);
- Serial.print('-');
- Serial.print(p1);
- Serial.print('-');
- Serial.print(p1+1);
- Serial.print('-');
- Serial.print(p1+2);
- Serial.print('-');
- Serial.print(p1+3);
- Serial.print(' ');
- //Posicion Print
- Serial.print(x);
- Serial.print(' ');
- Serial.print(y);
- Serial.println();
- //Colision y
- if (y>=height-2 || y<=2) speedy=-speedy;
- //Colision barras
- int puntaje1=0, puntaje2=0;
- bool colision1=false,colision2=false;
- if ( ((y==p1-1) || (y==p1) || (y==p1+1) || (y==p1+2) || (y==p1+3)) && (x==2) ){
- colision1=true;
- }
- if ( ((y==p2-1) || (y==p2) || (y==p2+1) || (y==p2+2) || (y==p2+3)) && (x==width-3) ){
- //colision2=true;
- }
- if (colision1 || colision2 ) {
- speedx=-speedx;
- colision1=false;
- colision2=false;
- }
- //Colision afuera del juego
- else if (x>=width-1 || x<=0) {
- x=width/2;
- y=height/2;
- }
- //puntaje
- for (int i=0; i<puntaje1; i++){
- for (int j=0; j<puntaje2; j++){
- matrix.drawPixel(i+1, 0, 0xFFFF);
- matrix.drawPixel(width-j,0,0xFFFF);
- }
- }
- matrix.show();
- delay(100);
- }
- //Matrix Test
- /*for (int j=0; j<20; j++){
- for (int i=0; i<45; i++){
- //matrix.fillScreen(0);
- matrix.drawPixel(i,j,0xFFFF);
- matrix.show();
- x++; y++;
- delay(10);
- }
- }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement