Thank you to anyone who has already donated - your generous donations helped make three months of treatment possible.
My brother Nate continues to fight stage IV Hodgkin's lymphoma. He's just 31, with a wife and baby girl. They have no active income (since he's been unable to return to work), no insurance, and cannot afford the treatment he needs. Nate and his family need your help. Please consider a donation, every dollar helps. Thanks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
/* NTSC, take 2
* ---------------
* Created Sun Aug 26 14:59:29 EDT 2007
*
* (cleft) 2007 by Matthieu Lalonde
*
* Note: Ideal values for the resistors are 900ohm and 330ohm!
*
*/
// Définition des pins
// Definition of signal levels for the AD 2-bit converter
/* 0.00v */
/* 0.33v */
/* 0.67v */
/* 1.00v */
// Defines TV Modes
// Select a TV mode (PAL isn't implemented)
/* Includes the last 20 lines for the vertical sync! */
/* These 20 lines... */
// Prototypes
void startHSync(void);
void endHSync(void);
void generateVSync(void);
void writeBufferLine(int position);
void writeTVLines(void);
void clearFrameBuffer(boolean mode);
byte frameBuffer[_tvPixelWidth][_tvPixelHeight]; // Video frame buffer
char c; // Serial buffer
/**
NTSC Signal definition:
-- Horizontal sync (hsync) pulse: Start each scanline with 0.3V,
then 0V for 4.7us (microseconds), and then back to 0.3V. This tells the TV to start drawing a new scanline
-- The "Back Porch": A transition region of 0.3V for 5.9us between the
hsync pulse and the visible region, off the left edge of the TV
-- Visible scan region: This is the part you actually see.
0.3V shows up as black, 1V as white, everything in between is greyscale. The visible region lasts for 51.5us
-- The "Front Porch": A transition region of 0.3V for 1.4us before
the hsync pulse of the next line, off the right edge of the TV
-- Vertical sync (vsync) pulse: Lines 243-262 of each frame (off the bottom of the TV)
start with 0.3V for 4.7us, and the rest is 0V. This tells the TV to prepare for a new frame.
Think of it as just 0V with an inverted sync pulse
*** http://www.eyetap.org/ece385/lab5.htm ***
**/
// Writes each pixel of a line
void
{
unsigned int ii;
for
{
PORTB = frameBuffer[ii][position];
// Waste some time to make sure the line is sent with proper timing
if
delayMicroseconds((51.5 / _tvPixelWidth));
else
delayMicroseconds((_tvPixelWidth / 51.5));
}
}
// Generate sync pulse for a new line
void
{
// Begin H Sync
PORTB = _SYNC; delayMicroseconds(4.7);
// Back Porch
PORTB = _BLACK; delayMicroseconds(5.9);
// Visible scan (51.5µs) follows
}
// Generate sync pulse for the end of a line
void
{
// Front Porch
PORTB = _BLACK; delayMicroseconds(1.4);
}
// Generate sync pulse for the virtual sync (lasts 20 lines)
void
{
unsigned int ii;
for
{
// Begin V Sync
PORTB = _BLACK; delayMicroseconds(4.7);
PORTB = _SYNC; delayMicroseconds(58.8);
}
}
// Writes every line from what's inside the frameBuffer
void
{
unsigned int i;
for;i++) // Includes correction for the vertical sync
{
startHSync();
// Write the line
writeBufferLine(i>>4);
endHSync();
}
// Vertical Sync
generateVSync();
}
// Clears the frame buffer (if mode is true it will fill it with a chess board pattern)
void
{
byte index, index2;
for
{
for
{
if {
frameBuffer[index][index2] = _BLACK;
} else {
frameBuffer[index][index2] = (index + index2) % 3 + 1;
}
}
}
}
// Defines a static sprite
const static byte graphic[_tvPixelWidth][_tvPixelHeight] = {
{_WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK },
{_GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY },
{_BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE },
{_WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK },
{_GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY },
{_WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK },
{_GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY },
{_BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE },
{_WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK },
{_GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY },
{_BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE },
{_WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK },
{_GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY },
{_BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE },
{_WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK },
{_GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY },
{_BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE },
{_WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK },
{_GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY },
{_BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE, _BLACK, _WHITE },
{_GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY, _GRAY }};
void {
Serial.begin(_serialBauteRate);
Serial.println("Arduino Initialized!");
Serial.println((long int) (sizeof frameBuffer));
Serial.print("Mode: ");
pinMode(_pinVideo, OUTPUT);
pinMode(_pinSync, OUTPUT);
clearFrameBuffer(false);
frameBuffer[(_tvPixelWidth / 2)][(_tvPixelHeight / 2)] = _WHITE;
}
void {
// Write the tv lines
writeTVLines();
// Check for commands
if)
{
c = Serial.read();
switch
{
case 'c' :
Serial.println(); Serial.println("Clearing screen");
clearFrameBuffer(false);
break;
case 'f' :
Serial.println(); Serial.println("Filling with pattern");
clearFrameBuffer(true);
break;
case 'g' :
Serial.println(); Serial.println("Filling with graphic");
int ii,jj;
for
{
for(jj=0;jj<_tvPixelHeight;jj++)
{
frameBuffer[ii][jj] = graphic[ii][jj];
}
}
break;
default :
Serial.println();
Serial.println("c: clear screen | f: fille with pattern 1 | g: fill graphic pattern");
break;
}
Serial.print("Mode: ");
}
}
|