- 3D-Druck Einstieg und Tipps         
Ergebnis 1 bis 4 von 4

Thema: Arduino und pal

  1. #1
    Erfahrener Benutzer Roboter Genie
    Registriert seit
    30.12.2008
    Beiträge
    1.427

    Arduino und pal

    Anzeige

    Powerstation Test
    Hi eine frage an die PAl oder fbas experten und die bissel c kennen
    ich habe

    Code:
    //Arduino Tv framebuffer
    //Alastair Parker
    //2007
    
    // Video out voltage levels
    #define _SYNC 0x00
    #define _BLACK 0x01
    #define _GRAY 0x02
    #define _WHITE 0x03
    
    // dimensions of the screen
    #define WIDTH 38
    #define HEIGHT 14
    
    //number of lines to display
    #define DISPLAY_LINES 240
    
    // update speed for the main loop of the game
    #define UPDATE_INTERVAL 1
    
    // positions of the player paddles
    #define PLAYER_RIGHT_X 35
    #define PLAYER_LEFT_X 2
    
    // maximum velocity of the ball
    #define MAX_VEL 10
    
    
    //video pins
    #define DATA_PIN 9
    #define SYNC_PIN 8
    
    // the video frameBuffer
    byte frameBuffer[WIDTH][HEIGHT];
    
    // loop indices
    byte index, index2;
    
    // pal video line loop
    byte line;
    // current drawing line in framebuffer
    byte newLine;
    
    
    // if the left player should be updated or the right
    
    // if we should be waiting for something to happen
    boolean waiting=true;
    // if displaying the title
    boolean showingTitle = true;
    
    // value of the counter controlling the freq of updates
    byte updateCounter=0;
    
    
    // draw a pixel to the buffer
    void setPixel(byte x,byte y)
    {
    frameBuffer[x][y]= _WHITE;
    }
    
    void grayPixel(byte x, byte y)
    {
    frameBuffer[x][y]= _GRAY;
    }
    
    // draw a black pixel to the buffer
    void clearPixel(byte x,byte y)
    {
    frameBuffer[x][y]= _BLACK;
    }
    
    // draw a paddle
    void drawPaddle(byte x,byte y,byte col)
    {
    frameBuffer[x][y]= col;
    frameBuffer[x][y+1]= col;
    }
    
    
    //draw the title message
    void drawArduinoPong()
    {
    //arduino
    setPixel(7,3);
    setPixel(8,3);
    setPixel(15,3);
    setPixel(21,3);
    setPixel(6,4);
    setPixel(8,4);
    setPixel(14,4);
    setPixel(15,4);
    setPixel(28,4);
    setPixel(6,5);
    setPixel(7,5);
    setPixel(8,5);
    setPixel(10,5);
    setPixel(11,5);
    setPixel(13,5);
    setPixel(15,5);
    setPixel(17,5);
    setPixel(19,5);
    setPixel(21,5);
    setPixel(23,5);
    setPixel(24,5);
    setPixel(27,5);
    setPixel(29,5);
    setPixel(6,6);
    setPixel(8,6);
    setPixel(10,6);
    setPixel(14,6);
    setPixel(15,6);
    setPixel(18,6);
    setPixel(19,6);
    setPixel(21,6);
    setPixel(23,6);
    setPixel(25,6);
    setPixel(28,6);
    
    //pong
    setPixel(10,8);
    setPixel(11,8);
    setPixel(15,8);
    setPixel(16,8);
    setPixel(19,8);
    setPixel(22,8);
    setPixel(24,8);
    setPixel(25,8);
    setPixel(26,8);
    setPixel(10,9);
    setPixel(12,9);
    setPixel(14,9);
    setPixel(17,9);
    setPixel(19,9);
    setPixel(20,9);
    setPixel(22,9);
    setPixel(24,9);
    setPixel(10,10);
    setPixel(11,10);
    setPixel(14,10);
    setPixel(17,10);
    setPixel(19,10);
    setPixel(21,10);
    setPixel(22,10);
    setPixel(24,10);
    setPixel(26,10);
    setPixel(10,11);
    setPixel(15,11);
    setPixel(16,11);
    setPixel(19,11);
    setPixel(22,11);
    setPixel(24,11);
    setPixel(25,11);
    setPixel(26,11);
    }
    
    
    // clear the screen
    void clearScreen()
    {
    for (index = 0; index < WIDTH; index++)
    for (index2=0;index2<=HEIGHT;++index2)
    {
    frameBuffer[index][index2] = _BLACK;
    }
    }
    
    // the setup routine
    void setup()
    {
    //cli();
    pinMode (SYNC_PIN, OUTPUT);
    pinMode (DATA_PIN, OUTPUT);
    digitalWrite (SYNC_PIN, HIGH);
    digitalWrite (DATA_PIN, HIGH);
    
    clearScreen();
    drawArduinoPong();
    }
    
    void loop()
    {
    // iterate over the lines on the tv
    for ( line =0;line< DISPLAY_LINES;++line)
    {
    
    // HSync
    // front porch (1.5 us)
    PORTB = _BLACK;
    delayMicroseconds(1.5);
    //sync (4.7 us)
    PORTB = _SYNC;
    delayMicroseconds(4.7);
    // breezeway (.6us) + burst (2.5us) + colour back borch (1.6 us)
    PORTB = _BLACK;
    delayMicroseconds(0.6+2.5+1.6);
    
    
    //calculate which line to draw to
    newLine = line >>4;
    delayMicroseconds(1);
    
    //display the array for this line
    // a loop would have been smaller, but it messes the timing up
    PORTB = frameBuffer[0][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[1][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[2][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[3][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[4][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[5][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[6][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[7][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[8][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[9][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[10][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[11][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[12][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[13][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[14][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[15][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[16][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[17][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[18][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[19][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[20][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[21][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[22][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[23][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[24][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[25][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[26][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[27][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[28][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[29][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[30][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[31][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[32][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[33][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[34][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[35][newLine];
    delayMicroseconds(1);
    
    // klugdge to correct timings
    PORTB = frameBuffer[36][newLine];
    PORTB=PORTB;
    PORTB=PORTB;
    PORTB=PORTB;
    delayMicroseconds(3);
    }
    
    delayMicroseconds(10);
    //vsync
    PORTB = _SYNC;
    // remainder of sync period
    delayMicroseconds(250);
    
    
    }
    von http://sites.google.com/site/alastairparker/arduinopong hab den code bissel gekürtzt auf des wesentliche. jedoch hab ich kein sauberes bild mehr es stimmt irgendwas mit dem timing nicht mehr
    das bild rollt nicht sondern verzerrt werd mal noch ein foto machen fals es von nöten sein sollte

  2. #2
    Erfahrener Benutzer Roboter Genie
    Registriert seit
    30.12.2008
    Beiträge
    1.427
    zwischen durch was essen die pal richtlinien druchlesen und es geht
    Code:
    //Arduino Tv framebuffer
    //Alastair Parker
    //2007
    
    // Video out voltage levels
    #define _SYNC 0x00
    #define _BLACK 0x01
    #define _GRAY 0x02
    #define _WHITE 0x03
    
    // dimensions of the screen
    #define WIDTH 38
    #define HEIGHT 14
    
    //number of lines to display
    #define DISPLAY_LINES 240
    
    // update speed for the main loop of the game
    #define UPDATE_INTERVAL 1
    
    // positions of the player paddles
    #define PLAYER_RIGHT_X 35
    #define PLAYER_LEFT_X 2
    
    // maximum velocity of the ball
    #define MAX_VEL 10
    
    
    //video pins
    #define DATA_PIN 9
    #define SYNC_PIN 8
    
    // the video frameBuffer
    byte frameBuffer[WIDTH][HEIGHT];
    
    // loop indices
    byte index, index2;
    
    // pal video line loop
    byte line;
    // current drawing line in framebuffer
    byte newLine;
    
    
    // if the left player should be updated or the right
    
    // if we should be waiting for something to happen
    boolean waiting=true;
    // if displaying the title
    boolean showingTitle = true;
    
    // value of the counter controlling the freq of updates
    byte updateCounter=0;
    
    
    // draw a pixel to the buffer
    void setPixel(byte x,byte y)
    {
    frameBuffer[x][y]= _WHITE;
    }
    
    void grayPixel(byte x, byte y)
    {
    frameBuffer[x][y]= _GRAY;
    }
    
    // draw a black pixel to the buffer
    void clearPixel(byte x,byte y)
    {
    frameBuffer[x][y]= _BLACK;
    }
    
    // draw a paddle
    void drawPaddle(byte x,byte y,byte col)
    {
    frameBuffer[x][y]= col;
    frameBuffer[x][y+1]= col;
    }
    
    
    //draw the title message
    void drawArduinoPong()
    {
    //arduino
    setPixel(7,3);
    setPixel(8,3);
    setPixel(15,3);
    setPixel(21,3);
    setPixel(6,4);
    setPixel(8,4);
    setPixel(14,4);
    setPixel(15,4);
    setPixel(28,4);
    setPixel(6,5);
    setPixel(7,5);
    setPixel(8,5);
    setPixel(10,5);
    setPixel(11,5);
    setPixel(13,5);
    setPixel(15,5);
    setPixel(17,5);
    setPixel(19,5);
    setPixel(21,5);
    setPixel(23,5);
    setPixel(24,5);
    setPixel(27,5);
    setPixel(29,5);
    setPixel(6,6);
    setPixel(8,6);
    setPixel(10,6);
    setPixel(14,6);
    setPixel(15,6);
    setPixel(18,6);
    setPixel(19,6);
    setPixel(21,6);
    setPixel(23,6);
    setPixel(25,6);
    setPixel(28,6);
    
    //pong
    setPixel(10,8);
    setPixel(11,8);
    setPixel(15,8);
    setPixel(16,8);
    setPixel(19,8);
    setPixel(22,8);
    setPixel(24,8);
    setPixel(25,8);
    setPixel(26,8);
    setPixel(10,9);
    setPixel(12,9);
    setPixel(14,9);
    setPixel(17,9);
    setPixel(19,9);
    setPixel(20,9);
    setPixel(22,9);
    setPixel(24,9);
    setPixel(10,10);
    setPixel(11,10);
    setPixel(14,10);
    setPixel(17,10);
    setPixel(19,10);
    setPixel(21,10);
    setPixel(22,10);
    setPixel(24,10);
    setPixel(26,10);
    setPixel(10,11);
    setPixel(15,11);
    setPixel(16,11);
    setPixel(19,11);
    setPixel(22,11);
    setPixel(24,11);
    setPixel(25,11);
    setPixel(26,11);
    }
    
    
    // clear the screen
    void clearScreen()
    {
    for (index = 0; index < WIDTH; index++)
    for (index2=0;index2<=HEIGHT;++index2)
    {
    frameBuffer[index][index2] = _BLACK;
    }
    }
    
    // the setup routine
    void setup()
    {
    //cli();
    pinMode (SYNC_PIN, OUTPUT);
    pinMode (DATA_PIN, OUTPUT);
    digitalWrite (SYNC_PIN, HIGH);
    digitalWrite (DATA_PIN, HIGH);
    
    clearScreen();
    drawArduinoPong();
    }
    
    void loop()
    {
    // iterate over the lines on the tv
    for ( line =0;line< DISPLAY_LINES;++line)
    {
    
    // HSync
    // front porch (1.5 us)
    PORTB = _BLACK;
    delayMicroseconds(1.5);
    //sync (4.7 us)
    PORTB = _SYNC;
    delayMicroseconds(4.7);
    // breezeway (.6us) + burst (2.5us) + colour back borch (1.6 us)
    PORTB = _BLACK;
    delayMicroseconds(0.6+2.5+1.6);
    
    
    //calculate which line to draw to
    newLine = line >>4;
    delayMicroseconds(1);
    
    //display the array for this line
    // a loop would have been smaller, but it messes the timing up
    PORTB = frameBuffer[0][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[1][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[2][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[3][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[4][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[5][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[6][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[7][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[8][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[9][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[10][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[11][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[12][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[13][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[14][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[15][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[16][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[17][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[18][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[19][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[20][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[21][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[22][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[23][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[24][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[25][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[26][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[27][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[28][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[29][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[30][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[31][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[32][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[33][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[34][newLine];
    delayMicroseconds(1);
    PORTB = frameBuffer[35][newLine];
    delayMicroseconds(1);
    
    // klugdge to correct timings
    PORTB = frameBuffer[36][newLine];
    PORTB=PORTB;
    PORTB=PORTB;
    PORTB=PORTB;
    delayMicroseconds(3);
    }
    
    delayMicroseconds(12);
    //vsync
    PORTB = _SYNC;
    // remainder of sync period
    delayMicroseconds(250);
    
    
    }
    für den zeilenrücklauf waren im spiel pinpong 10µS eingeplant weil da noch paar if abfragen kamen die bei mir weggefallen waren also musst ich 12µS nehmen und es ging außerdem hatt ich noch ein widerstandsproblem
    so jetzt gehts ich werd noch mal eine Bascom version erstellen oder gibt es da schon eine?

  3. #3
    Moderator Robotik Visionär Avatar von radbruch
    Registriert seit
    27.12.2006
    Ort
    Stuttgart
    Alter
    61
    Beiträge
    5.799
    Blog-Einträge
    8
    Hallo

    Na, das ist ja schön, wenn es nun funktioniert. Weil ich das auch schon immer mal versuchen wollte, kann es sicher nicht schaden, wenn ich mich nun eher unnötig durch die zwei Programmversionen durchgewühlt habe. Auch wenn du es selbst gefunden hast, ich habe dadurch auch was gelernt ;)

    Mit welchem Takt läuft denn das Board? Wo und wie ist delayMicroseconds() definiert? Welche Widerstände verwendest du jetzt? (Warum gibt es im Code keine Includes von Libraries?)

    Gruß

    mic
    Bild hier  
    Atmel’s products are not intended, authorized, or warranted for use
    as components in applications intended to support or sustain life!

  4. #4
    Erfahrener Benutzer Roboter Genie
    Registriert seit
    30.12.2008
    Beiträge
    1.427
    das board läuft mit 16Mhz
    die delayMicroseconds() gehört zum arduino c schon dazu und heist warte genau x mikrosekunden
    http://www.arduino.cc/cgi-bin/yabb2/...num=1166667354
    ich selbst hab die werte mit drehpotis eingestellt weil ich kaum widerstände hab
    ich werd eine bascomversion spätestens in den osterferien schreiben aber ich denke da werd ich einen atmega8 nehmen und den dann noch bissel übertakten um noch höhere auflösungen hinzubekommen.

    http://images.google.de/imgres?imgur...26tbs%3Disch:1

    da stand das auch mit den 12µS für den zeilenrücklauf.

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •  

LiFePO4 Speicher Test