Arduino Composite Video

Television! Teacher, mother, secret lover. –Homer J. Simpson

Having only discovered the duino recently, I’m constantly searching for applications that push the limits of what can be done with the device. There have been several sketches posted that will output composite black and white video to your TV with a very simple circuit, but the most interesting of these to me is the Arduino Pong code by Alastair Parker. What I’ve done is strip the code down to just the intro screen in order to simplify the idea and get my mind wrapped around it. Check out the following schematic, code and resulting output.

Download the code.

Arduino Composite Video Schematic

Arduino Composite Video Schematic

To change the on-screen text, grab a sheet of graph paper, create a rectangle that is 38 units wide and 14 units tall, and mark the pixels you would like to turn on. After that, it’s simply a matter of changing the “setPixel(x,y)” lines in the code. Have fun and as Homer says: Let us all bask in television’s warm glowing warming glow.

Composite Output Result

Composite Output Result

The circuit on breadboard

The circuit on breadboard

 

14 Responses to “Arduino Composite Video”

  1. Jeff Atkinson Says:

    Can you tell me who did your layout? I’ve been looking for one kind of like yours. Thank you.

  2. droops Says:

    I can not wait to see this in action this weekend. I may not be able to contain myself and break down and cut up an rca cable.

  3. riscphree Says:

    Looks good. Haven’t seen an Arduino do video stuff yet, I might have to turn my ybox-2 into an Arduino version …

  4. wolfgang Says:

    hi,
    i did also some stripping on a parkers code a few moths ago.
    this code should display input from the serial port. some kind of a tv -out console for arduino.

    //Arduino Tv framebuffer
    //Alastair Parker
    //2007

    // Video out voltage levels
    #define _SYNC 0×00
    #define _BLACK 0×01
    #define _GRAY 0×02
    #define _WHITE 0×03

    // dimensions of the screen
    #define WIDTH 38
    #define HEIGHT 14

    //number of lines to display
    #define DISPLAY_LINES 240 // weil NTSC?

    //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;

    int incomingByte = 0; // for incoming serial data

    int curx = 3; // cursorposx
    int cury = 2; //cursorpos y
    int xwert;
    int ywert;

    // draw a pixel to the buffer
    void setPixel(byte x,byte y)
    {
    xwert = curx + x;
    ywert = cury + y;
    frameBuffer[xwert][ywert]= _BLACK;
    }

    //draw it black
    void bsetPixel(byte x,byte y)
    {
    xwert = curx + x;
    ywert = cury + y;
    frameBuffer[xwert][ywert] = _WHITE;
    }

    void nextpos (int wert){
    if (curx > 30 ){ //unten weiter oder wieder rauf?

    if (cury == 2) {
    // curpos = point(2,8)
    curx = 3;
    cury = 8;
    }
    else if (cury == 8) {
    //curpos = point(2,2)
    curx = 3;
    cury = 2;
    //setChar (32);
    // setChar (32);
    // setChar (32);
    }
    }
    else {
    curx = curx + wert;
    }
    Serial.println(curx, DEC);
    }

    void setChar (int num){
    // if ((num > 44) && (num < 91)) { // alle voll
    //cleanpos (4,5);
    bsetPixel (0,0);
    bsetPixel (0,1);
    bsetPixel (0,2);
    bsetPixel (0,3);
    bsetPixel (0,4);

    bsetPixel (1,0);
    bsetPixel (1,1);
    bsetPixel (1,2);
    bsetPixel (1,3);
    bsetPixel (1,4);

    bsetPixel (2,0);
    bsetPixel (2,1);
    bsetPixel (2,2);
    bsetPixel (2,3);
    bsetPixel (2,4);
    // }

    if ( num == 32){//SPACE
    setPixel (0,0);
    setPixel (0,1);
    setPixel (0,2);
    setPixel (0,3);
    setPixel (0,4);

    setPixel (1,0);
    setPixel (1,1);
    setPixel (1,2);
    setPixel (1,3);
    setPixel (1,4);

    setPixel (2,0);
    setPixel (2,1);
    setPixel (2,2);
    setPixel (2,3);
    setPixel (2,4);

    }

    if ( num == 65 ){//A
    setPixel (1,1);
    setPixel (1,3);
    setPixel (1,4);
    }

    if ( num == 66){//B
    setPixel (1,1);
    setPixel (1,3);
    setPixel (2,0);
    setPixel (2,4);
    }
    if ( num == 67 ){//C
    setPixel (1,1);
    setPixel (1,2);
    setPixel (1,3);
    setPixel (2,1);
    setPixel (2,2);
    setPixel (2,3);
    }
    if ( num == 68 ){//D
    setPixel (1,1);
    setPixel (1,2);
    setPixel (1,3);
    setPixel (2,0);
    setPixel (2,4);
    }
    if ( num == 69 ){//E
    setPixel (1,1);

    setPixel (1,3);
    setPixel (2,1);
    setPixel (2,2);
    setPixel (2,3);
    }
    if ( num == 70 ){//F
    setPixel (1,1);

    setPixel (1,3);
    setPixel (1,4);
    setPixel (2,1);
    setPixel (2,2);
    setPixel (2,3);
    setPixel (2,4);
    }
    if ( num == 71 ){//G
    setPixel (1,1);
    setPixel (1,3);
    setPixel (2,1);
    }

    if ( num == 72 ){//H
    setPixel (1,0);
    setPixel (1,1);
    setPixel (1,3);
    setPixel (1,4);
    }
    if (num == 73 ){//I
    setPixel (0,0);
    setPixel (0,1);
    setPixel (0,2);
    setPixel (0,3);
    setPixel (0,4);
    setPixel (2,0);
    setPixel (2,1);
    setPixel (2,2);
    setPixel (2,3);
    setPixel (2,4);
    }
    if (num == 74){//J
    setPixel (0,0);
    setPixel (0,1);
    setPixel (0,2);
    setPixel (0,3);
    setPixel (2,0);
    setPixel (2,1);
    setPixel (2,2);
    setPixel (2,3);
    setPixel (2,4);
    }

    if ( num == 75 ){//K
    setPixel (1,0);
    setPixel (1,2);
    setPixel (1,4);

    setPixel (2,1);
    setPixel (2,2);
    setPixel (2,3);

    }

    if ( num == 76 ){//L
    setPixel (1,0);
    setPixel (1,1);
    setPixel (1,2);
    setPixel (1,3);
    setPixel (2,0);
    setPixel (2,1);
    setPixel (2,2);
    setPixel (2,3);
    }
    if ( num == 77 ){//M
    setPixel (1,0);
    setPixel (1,2);
    setPixel (1,3);
    setPixel (1,4);
    }
    if ( num == 78 ){//N
    setPixel (1,0);
    setPixel (1,2);
    setPixel (1,3);
    setPixel (1,4);
    setPixel (2,0);
    setPixel (2,1);
    }

    if ( num == 79 ){//O
    setPixel (0,0);
    setPixel (0,4);
    setPixel (1,1);
    setPixel (1,2);
    setPixel (1,3);
    setPixel (2,0);
    setPixel (2,4);
    }

    if ( num == 80 ){//P
    setPixel (1,1);
    setPixel (1,3);
    setPixel (1,4);
    setPixel (2,3);
    setPixel (2,4);
    }

    if ( num == 81 ){//Q
    setPixel (0,0);
    setPixel (0,4);
    setPixel (1,1);
    setPixel (1,2);
    setPixel (1,3);
    setPixel (2,0);
    }
    if ( num == 82 ){//R
    setPixel (1,1);
    //setPixel (1,3);
    setPixel (1,4);
    setPixel (2,3);
    }

    if ( num == 83 ){//S
    //setPixel (0,0);
    setPixel (0,3);
    setPixel (1,1);
    setPixel (1,3);
    setPixel (2,1);
    //setPixel (2,2);
    }

    if ( num == 84 ){//T
    setPixel (0,1);
    setPixel (0,2);
    setPixel (0,3);
    setPixel (0,4);
    setPixel (2,1);
    setPixel (2,2);
    setPixel (2,3);
    setPixel (2,4);
    }
    if ( num == 85 ){//U
    setPixel (1,0);
    setPixel (1,1);
    setPixel (1,2);
    setPixel (1,3);
    }

    if ( num == 86 ){//V
    setPixel (0,4);
    setPixel (1,0);
    setPixel (1,1);
    setPixel (1,2);
    setPixel (1,3);
    setPixel (2,4);

    }
    if ( num == 87 ){//W
    setPixel (1,0);
    setPixel (1,1);
    setPixel (1,2);
    setPixel (1,4);
    }

    if ( num == 88 ){//X
    setPixel (1,0);
    setPixel (1,1);
    setPixel (1,3);
    setPixel (1,4);
    setPixel (0,2);
    setPixel (2,2);
    }

    if ( num == 89 ){//Y
    setPixel (0,2);
    setPixel (0,3);
    setPixel (0,4);
    setPixel (1,0);
    setPixel (1,1);
    setPixel (2,2);
    setPixel (2,3);
    setPixel (2,4);
    }

    if ( num == 90 ){//Z
    setPixel (0,1);
    setPixel (0,2);
    setPixel (1,1);
    setPixel (1,3);
    setPixel (2,2);
    setPixel (2,3);
    }

    if ( num == 48 ){//0
    setPixel (1,1);
    setPixel (1,2);
    setPixel (1,3);
    }

    if ( num == 49 ){//1
    setPixel (0,1);
    setPixel (0,2);
    setPixel (0,3);
    setPixel (0,4);
    setPixel (2,0);
    setPixel (2,1);
    setPixel (2,2);
    setPixel (2,3);
    setPixel (2,4);
    }

    if ( num == 50 ){//2
    setPixel (0,1);
    setPixel (1,1);
    setPixel (1,3);
    setPixel (2,3);
    }

    if ( num == 51 ){//3
    setPixel (0,1);
    setPixel (1,1);
    setPixel (0,3);
    setPixel (1,3);
    }

    if ( num == 52 ){//4
    setPixel (0,3);
    setPixel (0,4);
    setPixel (1,0);
    setPixel (1,1);
    setPixel (1,3);
    setPixel (1,4);
    setPixel (2,0);
    }

    if ( num == 53 ){//5
    setPixel (0,3);
    setPixel (1,1);
    setPixel (1,3);
    setPixel (2,1);
    setPixel (2,2);
    }

    if ( num == 54 ){//6
    setPixel (1,0);
    setPixel (1,1);
    setPixel (1,3);
    setPixel (2,0);
    setPixel (2,1);
    setPixel (2,2);
    }

    if ( num == 55 ){//7
    setPixel (0,1);
    setPixel (0,2);
    setPixel (0,3);
    setPixel (0,4);
    setPixel (1,1);
    setPixel (1,2);
    setPixel (1,3);
    setPixel (1,4);
    }

    if ( num == 56 ){//8
    setPixel (1,1);
    setPixel (1,3);
    }

    if ( num == 57 ){//9
    setPixel (0,3);
    setPixel (1,1);
    setPixel (1,3);
    }

    if ( num == 58 ){//:
    setPixel (0,0);
    setPixel (0,1);
    // setPixel (0,2);
    setPixel (0,3);
    setPixel (1,0);
    setPixel (1,1);
    setPixel (1,2);
    setPixel (1,3);
    setPixel (1,4);
    setPixel (2,0);
    setPixel (2,1);
    setPixel (2,2);
    setPixel (2,3);
    setPixel (2,4);
    }

    if ( num == 45 ){//-
    setPixel (0,0);
    setPixel (0,1);
    setPixel (1,0);
    setPixel (1,1);
    setPixel (2,0);
    setPixel (2,1);

    setPixel (0,3);
    setPixel (0,4);
    setPixel (1,3);
    setPixel (1,4);
    setPixel (2,3);
    setPixel (2,4);
    }

    if ( num == 46 ){//.
    setPixel (0,0);
    setPixel (0,1);
    setPixel (0,2);
    setPixel (0,3);
    setPixel (1,0);
    setPixel (1,1);
    setPixel (1,2);
    setPixel (1,3);
    setPixel (1,4);
    setPixel (2,0);
    setPixel (2,1);
    setPixel (2,2);
    setPixel (2,3);
    setPixel (2,4);
    }

    if ( num == 47 ){//. / SCHRÄG
    setPixel (0,0);
    setPixel (0,1);
    setPixel (0,2);
    //setPixel (0,3);
    setPixel (0,4);
    setPixel (1,0);
    setPixel (1,1);
    // setPixel (1,2);
    setPixel (1,3);
    setPixel (1,4);
    setPixel (2,0);
    // setPixel (2,1);
    setPixel (2,2);
    setPixel (2,3);
    setPixel (2,4);
    }

    nextpos(4);
    }

    // clear the screen
    void clearScreen()
    {
    curx = 3;
    cury = 2;

    for (index = 0; index < WIDTH; index++)
    for (index2=0;index2<=HEIGHT;++index2)
    {
    frameBuffer[index][index2] = _BLACK;
    }
    }

    // the setup routine
    void setup()
    {
    cli(); //That should disable the interrupts.

    //aber besser da seriell dann noch geht:

    // Edit the file lib/targets/arduino/wiring.c
    //and block comment out the following

    // enable timer 0 overflow interrupt
    //#if defined(__AVR_ATmega168__)
    // sbi(TIMSK0, TOIE0);
    //#else
    // sbi(TIMSK, TOIE0);
    //#endif

    pinMode (SYNC_PIN, OUTPUT);
    pinMode (DATA_PIN, OUTPUT);
    digitalWrite (SYNC_PIN, HIGH);
    digitalWrite (DATA_PIN, HIGH);
    Serial.begin(9600);
    clearScreen();

    //hallo
    setChar (72);
    setChar (65);
    setChar (76);
    setChar (76);
    setChar (79);

    //spaces
    setChar (32);
    setChar (32);
    setChar (32);
    setChar (32);

    //WOLFI
    setChar (87);
    setChar (79);
    setChar (76);
    setChar (70);
    setChar (73);
    /*
    //GERHARD
    setChar (71);
    setChar (69);
    setChar (82);
    setChar (72);
    setChar (65);
    setChar (82);
    setChar (68);

    setChar (66);
    setChar (65);
    setChar (66);
    setChar (69); */

    }

    void loop()
    {
    // iterate over the lines on the tv
    for ( line =0;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(1);
    delayMicroseconds(1);
    delayMicroseconds(1);
    }

    //vsync
    PORTB = _SYNC;

    // delayMicroseconds(305);

    delayMicroseconds(10);

    if (Serial.available() > 0) {
    // read the incoming byte:
    incomingByte = Serial.read();

    // say what you got:
    // Serial.print(”I received: “);
    // Serial.print(incomingByte);

    Serial.println(incomingByte, DEC);

    setChar (incomingByte);

    if (incomingByte == 99){ //1
    clearScreen();
    }
    // if (incomingByte == 50){ //2
    // drawArduinoPong();
    // }

    }

    }

  5. droops Says:

    awesome wolfgang!

  6. Shane Says:

    Wow!
    This reminds me of the old school graphics we used to have to do on the TRS-80 and Vic-20/C64.
    You would have to graph out all the letters, pictures and numbers on graph paper and depending on the system either set/unset or poke graphics memory sections to make the picture come out on the screen.
    Now we can do that with the duino…nice…

  7. Arduino composite video | SquareCows Says:

    [...] More about Arduino composite video [...]

  8. mightyOhm » Blog Archive » Composite Video with Arduino (Daily Duino) Says:

    [...] Having had some experience generating RGB video signals with the PIC, I have a deep appreciation for the work these guys did in not only generating composite video with an Arduino, but also making a Pong game.  The daily duino (need to bookmark that one) has a simpler example based on the same code. [...]

  9. Arduino composite video | eins78 Says:

    [...] More about Arduino composite video [...]

  10. drspectro Says:

    Not sure if this is reinventing the wheel, but I changed about 10 lines of your code to use the FrequencyTimer2 library for the vertical refresh interval. This triggers an interrupt whenever it is time to paint a new frame. Similar end result to Wolfgangs code, but doesnt require any edit to wiring.

    This allows you to put any code you want in main() since it will be interrupted whenever necessary by the timer.

    I moved the frame paint out of loop() and into a new routine DrawFrame(). Also had to comment out the cli() because DrawFrame is now called by an interrupt. I HAD to put an sei() interrupt enable at the end of DrawFrame, it appears sometimes the interrupts were defaulting to disabled at startup.

    FrequencyTimer2 is documented on the Arduino site.

    //further modified to use FrequencyTimer2 library
    //12/12/08 drspectro

    //Adapted by phizone from:
    //
    //Arduino Tv framebuffer
    //Alastair Parker
    //2007

    #include

    // Video out voltage levels
    #define _SYNC 0×00
    #define _BLACK 0×01
    #define _GRAY 0×02
    #define _WHITE 0×03

    // 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

    //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 displaying the title
    boolean showingTitle = true;

    // FrequencyTimer2 vars
    unsigned long temp;
    unsigned int xrand;
    unsigned int yrand;

    // 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 the title message
    void drawArduinoPong()
    {

    //DAILY
    setPixel(6,3);
    setPixel(7,3);
    setPixel(11,3);
    setPixel(12,3);
    setPixel(14,3);
    setPixel(15,3);
    setPixel(16,3);
    setPixel(18,3);
    setPixel(21,3);
    setPixel(23,3);
    setPixel(6,4);
    setPixel(8,4);
    setPixel(10,4);
    setPixel(12,4);
    setPixel(15,4);
    setPixel(18,4);
    setPixel(21,4);
    setPixel(22,4);
    setPixel(23,4);
    setPixel(6,5);
    setPixel(8,5);
    setPixel(10,5);
    setPixel(11,5);
    setPixel(12,5);
    setPixel(15,5);
    setPixel(18,5);
    setPixel(22,5);
    setPixel(6,6);
    setPixel(7,6);
    setPixel(10,6);
    setPixel(12,6);
    setPixel(14,6);
    setPixel(15,6);
    setPixel(16,6);
    setPixel(18,6);
    setPixel(19,6);
    setPixel(20,6);
    setPixel(22,6);

    //DUINO
    setPixel(9,8);
    setPixel(10,8);
    setPixel(13,8);
    setPixel(15,8);
    setPixel(17,8);
    setPixel(18,8);
    setPixel(19,8);
    setPixel(21,8);
    setPixel(24,8);
    setPixel(27,8);
    setPixel(28,8);
    setPixel(9,9);
    setPixel(11,9);
    setPixel(13,9);
    setPixel(15,9);
    setPixel(18,9);
    setPixel(21,9);
    setPixel(22,9);
    setPixel(24,9);
    setPixel(26,9);
    setPixel(29,9);
    setPixel(9,10);
    setPixel(11,10);
    setPixel(13,10);
    setPixel(15,10);
    setPixel(18,10);
    setPixel(21,10);
    setPixel(23,10);
    setPixel(24,10);
    setPixel(26,10);
    setPixel(29,10);
    setPixel(9,11);
    setPixel(10,11);
    setPixel(13,11);
    setPixel(14,11);
    setPixel(15,11);
    setPixel(17,11);
    setPixel(18,11);
    setPixel(19,11);
    setPixel(21,11);
    setPixel(24,11);
    setPixel(27,11);
    setPixel(28,11);
    }
    // clear the screen
    void clearScreen()
    {
    for (index = 0; index < WIDTH; index++)
    for (index2=0;index2<=HEIGHT;++index2)
    {
    frameBuffer[index][index2] = _BLACK;
    }
    }

    // draw video frame
    extern void DrawFrame(void)
    {
    // iterate over the lines on the tv

    //moved out of setup - only necessary if horizontal timing gets funky
    //cli();

    for ( line =0;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(2);
    }

    //vsync
    PORTB = _SYNC;

    // wait for the remainder of the sync period
    //delayMicroseconds(565);

    // needed sometimes interrupts seem to default to disabled
    sei();
    }

    // the setup routine
    void setup()
    {
    //cli();
    pinMode (SYNC_PIN, OUTPUT);
    pinMode (DATA_PIN, OUTPUT);
    digitalWrite (SYNC_PIN, HIGH);
    digitalWrite (DATA_PIN, HIGH);
    clearScreen();
    drawArduinoPong();

    // FrequencyTimer2 init
    FrequencyTimer2::setPeriod(16683);
    //FrequencyTimer2::setPeriod(16500); //16384
    temp = FrequencyTimer2::getPeriod();
    Serial.begin(9600);
    Serial.println(”Video Test”);
    Serial.println(temp);
    FrequencyTimer2::disable();
    FrequencyTimer2::setOnOverflow(DrawFrame);
    FrequencyTimer2::enable();
    }

    void loop()
    {
    // example code paints random pixels
    // insert your code here….
    while (1==1)
    {
    xrand = random(38);
    yrand = random(14);
    setPixel(xrand,yrand);
    xrand = random(38);
    yrand = random(14);
    clearPixel(xrand,yrand);
    };
    }

  11. drspectro Says:

    For some reason the include statement didnt paste right should be:
    include frequencytimer2.h

    needs to be enclosed in greater than/less than, but I dont know how to paste that.

  12. virtualuk Says:

    Forgive my ignorance, but would this work for NTSC if I were only to change the number of lines value or is it more involved than that?

  13. Phizone Says:

    It works on my NTSC set as written, so I’d say try it as is first.

  14. Brilldea Says:

    Hey, if you wanted you could use the 3.0″ LCD and driver board (accepts NTSC/PAL inputs) to create a portable Arduino gaming system. http://www.brilldea.com

Leave a Reply