├── AppleSlave └── AppleSlave.ino ├── Processing └── Esplora │ ├── Esplora_Processing.py │ ├── ex0 │ ├── Esplora_Processing$py.class │ ├── Esplora_Processing.py │ ├── ex0.pyde │ └── sketch.properties │ ├── ex1 │ ├── ex1.pyde │ └── sketch.properties │ ├── ex2 │ ├── ex2.pyde │ └── sketch.properties │ ├── ex3 │ ├── Esplora_Processing$py.class │ ├── Esplora_Processing.py │ ├── ex3.pyde │ └── sketch.properties │ ├── ex4 │ ├── Esplora_Processing$py.class │ ├── Esplora_Processing.py │ ├── ex4.pyde │ └── sketch.properties │ ├── ex5 │ ├── Esplora_Processing$py.class │ ├── Esplora_Processing.py │ └── ex5.pyde │ ├── ex6 │ ├── Esplora_Processing$py.class │ ├── Esplora_Processing.py │ ├── ex6.pyde │ └── sketch.properties │ └── ex7 │ ├── Esplora_Processing$py.class │ ├── Esplora_Processing.py │ ├── ex7.pyde │ └── sketch.properties ├── ProjectorControl ├── BENQ.gnumeric └── ProjectorControl.ino ├── PyEsplora ├── Esplora.py ├── ex.accel.py ├── ex.joystick.py ├── ex.rgb.py ├── ex.tft.py └── test.py ├── README.md ├── SIDrive └── SIDrive.ino ├── SerEsplora └── SerEsplora.ino └── VideoSPI ├── VideoSPI.ino └── chargen ├── chargen.h ├── chargen_reorder.h └── reorderROM.c /AppleSlave/AppleSlave.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Operate on FAT files on SD card from Apple II 3 | */ 4 | #define RTCLIB // Include RTC library? 5 | #define FAST_BUF_XFER // Buffer transfer with interrupts OFF in a polling loop 6 | #define TRISTATE_OUTPUT // Tristate output when not asserted 7 | #include 8 | const int sdSSpin = 10; // 4 for SD card on ethernet shield, 10 for SD card data logger shield 9 | /* 10 | * Access RTC on data logger shield 11 | */ 12 | #ifdef RTCLIB 13 | #include 14 | #include 15 | RTC_DS1307 rtc; 16 | #endif 17 | /* 18 | * Bit bang SPI slave mode for Apple II 19 | */ 20 | const int SSpin = 3; // PORTD.3 for Uno 21 | const int SCKpin = 6; // PORTD.6 for Uno 22 | const int MISOpin = 7; // PORTD.7 for Uno 23 | const int MOSIpin = 8; // PORTB.0 for Uno 24 | /* 25 | * SPI status 26 | */ 27 | const int SLAVE_BUSY = 0xFF; 28 | const int SLAVE_READY = '@'; 29 | const int SLAVE_ERROR = '!'; 30 | /* 31 | * Erros codes 32 | */ 33 | const int SLAVE_ERR_OK = 0; 34 | const int SLAVE_ERR_TIMEOUT = -1; 35 | const int SLAVE_ERR_BADVAL = -2; 36 | const int SLAVE_ERR_WAITING = -3; 37 | /* 38 | * SPI commands 39 | */ 40 | const int SLAVE_CMD_NOP = 0; 41 | const int SLAVE_CMD_ECHO = 1; 42 | const int SLAVE_CMD_HW = 2; 43 | 44 | const int SLAVE_CMD_PINMODE = 3; 45 | const int SLAVE_CMD_DIGREAD = 4; 46 | const int SLAVE_CMD_DIGWRITE = 5; 47 | const int SLAVE_CMD_ANAREAD = 6; 48 | const int SLAVE_CMD_PWMWRITE = 7; 49 | 50 | const int SLAVE_CMD_SERMODE = 8; 51 | const int SLAVE_CMD_SERAVAIL = 9; 52 | const int SLAVE_CMD_SERREAD = 10; 53 | const int SLAVE_CMD_SERWRITE = 11; 54 | 55 | const int SLAVE_CMD_BUFREAD = 12; 56 | const int SLAVE_CMD_BUFWRITE = 13; 57 | 58 | const int SLAVE_CMD_SDINIT = 14; 59 | const int SLAVE_CMD_CWD = 15; 60 | const int SLAVE_CMD_SDCHDIR = 16; 61 | const int SLAVE_CMD_SDMKDIR = 17; 62 | const int SLAVE_CMD_SDRMDIR = 18; 63 | const int SLAVE_CMD_SDRM = 19; 64 | const int SLAVE_CMD_SDREN = 20; 65 | const int SLAVE_CMD_SDOPEN = 21; 66 | const int SLAVE_CMD_SDOPENFIRST=22; 67 | const int SLAVE_CMD_SDOPENNEXT=23; 68 | const int SLAVE_CMD_SDCLOSE = 24; 69 | const int SLAVE_CMD_SDREAD = 25; 70 | const int SLAVE_CMD_SDWRITE = 26; 71 | const int SLAVE_CMD_SDSYNC = 27; 72 | const int SLAVE_CMD_SDREWIND = 28; 73 | const int SLAVE_CMD_SDSEEKOFS= 29; 74 | const int SLAVE_CMD_SDSEEKSET= 30; 75 | const int SLAVE_CMD_SDSEEKEOF= 31; 76 | const int SLAVE_CMD_SDPOS = 32; 77 | const int SLAVE_CMD_SDSIZE = 33; 78 | const int SLAVE_CMD_SDTRUNC = 34; 79 | const int SLAVE_CMD_SDISDIR = 35; 80 | const int SLAVE_CMD_SDISFILE = 36; 81 | const int SLAVE_CMD_SDEXISTS = 37; 82 | const int SLAVE_CMD_RTC = 38; 83 | const int SLAVE_CMD_RTCUPDATE= 39; 84 | /* 85 | * How long to wait in usec before timing out 86 | */ 87 | const unsigned long SLAVE_CMD_TIMEOUT = 10000UL; 88 | const unsigned long SLAVE_DATA_TIMEOUT = 100000UL; 89 | const int SLAVE_DELAY = 0xFF; 90 | /* 91 | * Arduino models 92 | */ 93 | const int HW_MODEL_UNO = 0x01; 94 | const int HW_MODEL_MEGA = 0x02; 95 | /* 96 | * Data transfer buffer 97 | */ 98 | const int MAX_BUF_SIZE = 512; 99 | byte xferBuf[MAX_BUF_SIZE]; 100 | /* 101 | * FAT file entries. One for directory, one for file 102 | */ 103 | SdFat sdFat; 104 | SdFile sdFile; 105 | bool sdInit = false; 106 | /* 107 | * Bit banged SPI data transfer variables 108 | */ 109 | volatile byte spiInput; 110 | volatile byte spiAvail = false; 111 | volatile byte spiOutput = SLAVE_BUSY; 112 | /* 113 | * Initialize it all 114 | */ 115 | void setup(void) 116 | { 117 | pinMode(SCKpin, INPUT); 118 | pinMode(SSpin, INPUT); 119 | pinMode(MOSIpin, INPUT); 120 | #ifdef TRISTATE_OUTPUT 121 | pinMode(MISOpin, INPUT); 122 | #else 123 | pinMode(MISOpin, OUTPUT); 124 | #endif 125 | digitalWrite(MISOpin, LOW); 126 | Serial.begin(9600); 127 | //attachInterrupt(digitalPinToInterrupt(SSpin), spiXfer, FALLING); 128 | EICRA = 0x0A; // Falling edge triggered IRQ 129 | EIMSK = 0x02; // INT1 enabled 130 | sdInit = sdFat.begin(sdSSpin, SPI_FULL_SPEED); 131 | spiReady(); 132 | 133 | #ifdef RTCLIB 134 | if (rtc.begin()) { 135 | if (! rtc.isrunning()) { 136 | // following line sets the RTC to the date & time this sketch was compiled 137 | rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); 138 | } 139 | } 140 | #endif 141 | } 142 | // 143 | // Shift in/out serial data 144 | // 145 | const int SLAVE_CLK_TIMEOUT = 0xFF; 146 | #define SCLK_FALL for(timeout=SLAVE_CLK_TIMEOUT;(PIND&0x40)&&timeout--;) 147 | #define SCLK_RISE for(timeout=SLAVE_CLK_TIMEOUT;!(PIND&0x40)&&timeout--;) 148 | ISR(INT1_vect) 149 | { 150 | #ifdef TRISTATE_OUTPUT 151 | DDRD |= 0x80; // Enable output 152 | #endif 153 | spiXfer(); 154 | EIFR=0x02; 155 | #ifdef TRISTATE_OUTPUT 156 | DDRD &= 0x7F; // Disable output 157 | PORTD &= 0x7F; // Tri-state 158 | #else 159 | PORTD |= 0x80; // SLAVE_BUSY 160 | #endif 161 | } 162 | void spiXfer(void) 163 | { 164 | byte outPort, spiSR; 165 | byte timeout; 166 | 167 | outPort = PORTD & 0x7F; 168 | spiSR = spiOutput; 169 | SCLK_FALL; 170 | PORTD = outPort | (spiSR & 0x80); 171 | spiSR = (spiSR << 1) | (PINB & 1); 172 | SCLK_RISE; 173 | SCLK_FALL; 174 | PORTD = outPort | (spiSR & 0x80); 175 | spiSR = (spiSR << 1) | (PINB & 1); 176 | SCLK_RISE; 177 | SCLK_FALL; 178 | PORTD = outPort | (spiSR & 0x80); 179 | spiSR = (spiSR << 1) | (PINB & 1); 180 | SCLK_RISE; 181 | SCLK_FALL; 182 | PORTD = outPort | (spiSR & 0x80); 183 | spiSR = (spiSR << 1) | (PINB & 1); 184 | SCLK_RISE; 185 | SCLK_FALL; 186 | PORTD = outPort | (spiSR & 0x80); 187 | spiSR = (spiSR << 1) | (PINB & 1); 188 | SCLK_RISE; 189 | SCLK_FALL; 190 | PORTD = outPort | (spiSR & 0x80); 191 | spiSR = (spiSR << 1) | (PINB & 1); 192 | SCLK_RISE; 193 | SCLK_FALL; 194 | PORTD = outPort | (spiSR & 0x80); 195 | spiSR = (spiSR << 1) | (PINB & 1); 196 | SCLK_RISE; 197 | SCLK_FALL; 198 | PORTD = outPort | (spiSR & 0x80); 199 | spiSR = (spiSR << 1) | (PINB & 1); 200 | if (!spiAvail) 201 | { 202 | spiAvail = true; 203 | spiInput = spiSR; 204 | spiOutput = SLAVE_BUSY; 205 | } 206 | for (timeout = 0xFF;!(PIND&0x08) && timeout--;); // wait for SS de-assert 207 | } 208 | /* 209 | * SPI slave to Apple II 210 | */ 211 | int spiReadByte(unsigned long timeout, int nextOut) 212 | { 213 | unsigned long start = micros(); 214 | byte readByte; 215 | 216 | do { 217 | if (spiAvail) 218 | { 219 | spiOutput = nextOut; 220 | readByte = spiInput; 221 | spiAvail = false; 222 | return readByte; 223 | } 224 | } while (micros() - start < timeout); 225 | return SLAVE_ERR_TIMEOUT; 226 | } 227 | int spiWriteByte(byte writeByte, unsigned long timeout) 228 | { 229 | unsigned long start = micros(); 230 | byte readByte; 231 | 232 | noInterrupts(); 233 | spiOutput = writeByte; 234 | spiAvail = false; 235 | interrupts(); 236 | do 237 | { 238 | if (spiAvail) 239 | { 240 | readByte = spiInput; 241 | spiAvail = false; 242 | return readByte; 243 | } 244 | } while (micros() - start < timeout); 245 | return SLAVE_ERR_TIMEOUT; 246 | } 247 | void spiBusy(void) 248 | { 249 | spiOutput = SLAVE_BUSY; 250 | #ifndef TRISTATE 251 | PORTD |= 0x80; // SLAVE_BUSY 252 | #endif 253 | } 254 | void spiReady(void) 255 | { 256 | noInterrupts(); 257 | spiOutput = SLAVE_READY; 258 | spiAvail = false; 259 | interrupts(); 260 | } 261 | void loop(void) 262 | { 263 | int cmd, pin, data, count; 264 | byte *pBuf; 265 | 266 | cmd = spiReadByte(0, SLAVE_READY); 267 | if (cmd >= 0) 268 | { 269 | switch (cmd) 270 | { 271 | case SLAVE_CMD_NOP: 272 | //Serial.println("Cmd: NOP"); 273 | break; 274 | case SLAVE_CMD_ECHO: 275 | data = spiReadByte(SLAVE_CMD_TIMEOUT, SLAVE_READY); 276 | if (data >= 0) 277 | spiWriteByte(data, SLAVE_CMD_TIMEOUT); 278 | spiReady(); 279 | break; 280 | case SLAVE_CMD_HW: 281 | spiWriteByte(HW_MODEL_UNO , SLAVE_CMD_TIMEOUT); 282 | spiReady(); 283 | break; 284 | case SLAVE_CMD_PINMODE: 285 | pin = spiReadByte(SLAVE_CMD_TIMEOUT, SLAVE_READY); 286 | data = spiReadByte(SLAVE_CMD_TIMEOUT, SLAVE_READY); 287 | if (pin >=0 && data >= 0) 288 | pinMode(pin, data); 289 | break; 290 | case SLAVE_CMD_DIGREAD: 291 | pin = spiReadByte(SLAVE_CMD_TIMEOUT, SLAVE_BUSY); 292 | spiWriteByte(digitalRead(pin), SLAVE_CMD_TIMEOUT); 293 | spiReady(); 294 | break; 295 | case SLAVE_CMD_DIGWRITE: 296 | pin = spiReadByte(SLAVE_CMD_TIMEOUT, SLAVE_READY); 297 | data = spiReadByte(SLAVE_CMD_TIMEOUT, SLAVE_READY); 298 | if (pin >= 0 && data >= 0) 299 | digitalWrite(pin, data & HIGH); 300 | break; 301 | case SLAVE_CMD_ANAREAD: 302 | pin = spiReadByte(SLAVE_CMD_TIMEOUT, SLAVE_BUSY); 303 | data = analogRead(pin); 304 | if (spiWriteByte(data >> 8, SLAVE_DATA_TIMEOUT) >= 0) 305 | spiWriteByte(data, SLAVE_CMD_TIMEOUT); 306 | spiReady(); 307 | break; 308 | case SLAVE_CMD_PWMWRITE: 309 | pin = spiReadByte(SLAVE_CMD_TIMEOUT, SLAVE_READY); 310 | data = spiReadByte(SLAVE_CMD_TIMEOUT, SLAVE_READY); 311 | if (pin >= 0 && data >= 0) 312 | analogWrite(pin, data); 313 | break; 314 | case SLAVE_CMD_SERMODE: 315 | break; 316 | case SLAVE_CMD_SERAVAIL: 317 | spiBusy(); 318 | data = Serial.available(); 319 | spiWriteByte(data, SLAVE_DATA_TIMEOUT); 320 | spiReady(); 321 | break; 322 | case SLAVE_CMD_SERREAD: 323 | spiBusy(); 324 | data = Serial.read(); 325 | spiWriteByte(data, SLAVE_DATA_TIMEOUT); 326 | spiReady(); 327 | break; 328 | case SLAVE_CMD_SERWRITE: 329 | data = spiReadByte(SLAVE_CMD_TIMEOUT, SLAVE_READY); 330 | if (data >= 0) 331 | Serial.write(data); 332 | break; 333 | case SLAVE_CMD_BUFREAD: 334 | count = (spiReadByte(SLAVE_CMD_TIMEOUT, SLAVE_READY) << 8) 335 | | spiReadByte(SLAVE_CMD_TIMEOUT, SLAVE_BUSY); 336 | if (count > MAX_BUF_SIZE) 337 | count = MAX_BUF_SIZE; 338 | /* 339 | * Uno goes out to lunch for awhile during back-to-back xfers. Not sure why 340 | */ 341 | #ifdef FAST_BUF_XFER 342 | noInterrupts(); 343 | #ifdef TRISTATE_OUTPUT 344 | DDRD |= 0x80; // Enable output 345 | #endif 346 | for (pBuf = xferBuf; count--; pBuf++) 347 | { 348 | unsigned int timeout; 349 | 350 | spiOutput = *pBuf; 351 | spiAvail = false; 352 | for (timeout = 0xFFFF;(PIND&0x08) && timeout--;); // wait for SS assert 353 | spiXfer(); 354 | } 355 | EIFR = 0x02; // clear pending interrupt 356 | #ifdef TRISTATE_OUTPUT 357 | DDRD &= 0x7F; // Disable output 358 | PORTD &= 0x7F; // Tri-state 359 | #else 360 | PORTD |= 0x80; // SLAVE_BUSY 361 | #endif 362 | interrupts(); 363 | #else 364 | for (pBuf = xferBuf; count--; pBuf++) 365 | if (spiWriteByte(*pBuf, SLAVE_DATA_TIMEOUT) < 0) 366 | break; 367 | #endif 368 | spiReady(); 369 | break; 370 | case SLAVE_CMD_BUFWRITE: 371 | count = (spiReadByte(SLAVE_CMD_TIMEOUT, SLAVE_READY) << 8) 372 | | spiReadByte(SLAVE_CMD_TIMEOUT, SLAVE_BUSY); 373 | if (count >= MAX_BUF_SIZE) 374 | count = MAX_BUF_SIZE; 375 | else 376 | xferBuf[count] = 0; // NULL terminate xfer, just for fun 377 | /* 378 | * Uno goes out to lunch for awhile during back-to-back xfers. Not sure why 379 | */ 380 | #ifdef FAST_BUF_XFER 381 | noInterrupts(); 382 | #ifdef TRISTATE_OUTPUT 383 | DDRD |= 0x80; // Enable output 384 | #endif 385 | for (pBuf = xferBuf; count--; pBuf++) 386 | { 387 | unsigned int timeout; 388 | 389 | spiOutput = SLAVE_READY; 390 | spiAvail = false; 391 | for (timeout = 0xFFFF;(PIND&0x08) && timeout--;); // wait for SS assert 392 | spiXfer(); 393 | *pBuf = spiInput; 394 | } 395 | EIFR = 0x02; // clear pending interrupt 396 | #ifdef TRISTATE_OUTPUT 397 | DDRD &= 0x7F; // Disable output 398 | PORTD &= 0x7F; // Tri-state 399 | #else 400 | PORTD |= 0x80; // SLAVE_BUSY 401 | #endif 402 | spiOutput = SLAVE_READY; 403 | spiAvail = false; 404 | interrupts(); 405 | #else 406 | for (pBuf = xferBuf; count--; pBuf++) 407 | { 408 | data = spiReadByte(SLAVE_DATA_TIMEOUT, SLAVE_READY); 409 | if (data < 0) 410 | { 411 | spiReady(); 412 | break; 413 | } 414 | *pBuf = data; 415 | } 416 | #endif 417 | break; 418 | case SLAVE_CMD_SDINIT: 419 | spiBusy(); 420 | if (!sdInit) 421 | sdInit = sdFat.begin(sdSSpin, SPI_FULL_SPEED); 422 | sdFile.close(); 423 | sdFat.chdir("/", true); 424 | sdFat.vwd()->rewind(); 425 | spiWriteByte(sdInit ? SLAVE_READY : SLAVE_ERROR, SLAVE_DATA_TIMEOUT); 426 | spiReady(); 427 | break; 428 | case SLAVE_CMD_CWD: 429 | spiBusy(); 430 | count = 0; 431 | if (sdFat.vwd()->getName((char *)xferBuf, 255)) 432 | count = strlen((char *)xferBuf); 433 | spiWriteByte(count, SLAVE_DATA_TIMEOUT); 434 | spiReady(); 435 | break; 436 | case SLAVE_CMD_SDCHDIR: 437 | spiBusy(); 438 | spiWriteByte(sdFat.chdir((char *)xferBuf, true), SLAVE_DATA_TIMEOUT); 439 | spiReady(); 440 | break; 441 | case SLAVE_CMD_SDMKDIR: 442 | spiBusy(); 443 | spiWriteByte(sdFat.mkdir((char *)xferBuf, true), SLAVE_DATA_TIMEOUT); 444 | spiReady(); 445 | break; 446 | case SLAVE_CMD_SDRMDIR: 447 | spiBusy(); 448 | spiWriteByte(sdFat.rmdir((char *)xferBuf), SLAVE_DATA_TIMEOUT); 449 | spiReady(); 450 | break; 451 | case SLAVE_CMD_SDRM: 452 | spiBusy(); 453 | spiWriteByte(sdFile.remove(), SLAVE_DATA_TIMEOUT); 454 | spiReady(); 455 | break; 456 | case SLAVE_CMD_SDREN: 457 | spiBusy(); 458 | spiWriteByte(sdFile.rename(sdFat.vwd(), (char *)xferBuf), SLAVE_DATA_TIMEOUT); 459 | spiReady(); 460 | break; 461 | case SLAVE_CMD_SDOPENFIRST: 462 | spiBusy(); 463 | sdFat.vwd()->rewind(); 464 | case SLAVE_CMD_SDOPENNEXT: 465 | spiBusy(); 466 | count = 0; 467 | if (sdFile.openNext(sdFat.vwd(), O_READ) && sdFile.getName((char *)xferBuf, 255)) 468 | count = strlen((char *)xferBuf); 469 | spiWriteByte(count, SLAVE_DATA_TIMEOUT); 470 | spiReady(); 471 | break; 472 | case SLAVE_CMD_SDOPEN: 473 | data = spiReadByte(SLAVE_CMD_TIMEOUT, SLAVE_BUSY); 474 | if (data == 0) 475 | data = O_READ; 476 | spiWriteByte(sdFile.open((char *)xferBuf, data), SLAVE_DATA_TIMEOUT); 477 | spiReady(); 478 | break; 479 | case SLAVE_CMD_SDCLOSE: 480 | spiBusy(); 481 | sdFile.close(); 482 | spiReady(); 483 | break; 484 | case SLAVE_CMD_SDREAD: 485 | count = (spiReadByte(SLAVE_CMD_TIMEOUT, SLAVE_READY) << 8) 486 | | spiReadByte(SLAVE_CMD_TIMEOUT, SLAVE_BUSY); 487 | if (count > 0) 488 | { 489 | if (count > MAX_BUF_SIZE) 490 | count = MAX_BUF_SIZE; 491 | count = sdFile.read(xferBuf, count); 492 | if (spiWriteByte(count >> 8, SLAVE_DATA_TIMEOUT) >= 0) 493 | spiWriteByte(count, SLAVE_CMD_TIMEOUT); 494 | } 495 | spiReady(); 496 | break; 497 | case SLAVE_CMD_SDWRITE: 498 | count = (spiReadByte(SLAVE_CMD_TIMEOUT, SLAVE_READY) << 8) 499 | | spiReadByte(SLAVE_CMD_TIMEOUT, SLAVE_BUSY); 500 | if (count > 0) 501 | { 502 | if (count > MAX_BUF_SIZE) 503 | count = MAX_BUF_SIZE; 504 | count = sdFile.write(xferBuf, count); 505 | if (count < 0) 506 | count = 0; 507 | if (spiWriteByte(count >> 8, SLAVE_DATA_TIMEOUT) >= 0) 508 | spiWriteByte(count, SLAVE_CMD_TIMEOUT); 509 | } 510 | spiReady(); 511 | break; 512 | case SLAVE_CMD_SDSYNC: 513 | case SLAVE_CMD_SDREWIND: 514 | case SLAVE_CMD_SDSEEKOFS: 515 | case SLAVE_CMD_SDSEEKSET: 516 | case SLAVE_CMD_SDSEEKEOF: 517 | case SLAVE_CMD_SDPOS: 518 | case SLAVE_CMD_SDSIZE: 519 | case SLAVE_CMD_SDTRUNC: 520 | break; 521 | case SLAVE_CMD_SDISDIR: 522 | spiWriteByte(sdFile.isDir(), SLAVE_DATA_TIMEOUT); 523 | spiReady(); 524 | break; 525 | case SLAVE_CMD_SDISFILE: 526 | spiWriteByte(sdFile.isFile(), SLAVE_DATA_TIMEOUT); 527 | spiReady(); 528 | break; 529 | case SLAVE_CMD_SDEXISTS: 530 | break; 531 | #ifdef RTCLIB 532 | case SLAVE_CMD_RTC: 533 | { 534 | spiBusy(); 535 | DateTime now = rtc.now(); 536 | if (spiWriteByte(now.year() - 2000, SLAVE_DATA_TIMEOUT) >= 0) 537 | if (spiWriteByte(now.month(), SLAVE_DATA_TIMEOUT) >= 0) 538 | if (spiWriteByte(now.day(), SLAVE_DATA_TIMEOUT) >= 0) 539 | if (spiWriteByte(now.hour(), SLAVE_DATA_TIMEOUT) >= 0) 540 | if (spiWriteByte(now.minute(), SLAVE_DATA_TIMEOUT) >= 0) 541 | spiWriteByte(now.second(), SLAVE_DATA_TIMEOUT); 542 | spiReady(); 543 | } 544 | break; 545 | case SLAVE_CMD_RTCUPDATE: 546 | { 547 | byte year, month, day, hour, minute, second; 548 | 549 | if ((year = spiReadByte(SLAVE_DATA_TIMEOUT, SLAVE_READY)) >= 0) 550 | if ((month = spiReadByte(SLAVE_DATA_TIMEOUT, SLAVE_READY)) >= 0) 551 | if ((day = spiReadByte(SLAVE_DATA_TIMEOUT, SLAVE_READY)) >= 0) 552 | if ((hour = spiReadByte(SLAVE_DATA_TIMEOUT, SLAVE_READY)) >= 0) 553 | if ((minute = spiReadByte(SLAVE_DATA_TIMEOUT, SLAVE_READY)) >= 0) 554 | if ((second = spiReadByte(SLAVE_DATA_TIMEOUT, SLAVE_BUSY)) >= 0) 555 | rtc.adjust(DateTime(year+2000, month, day, hour, minute, second)); 556 | spiReady(); 557 | } 558 | break; 559 | #endif 560 | default: 561 | Serial.print("Huh? Cmd:");Serial.println(cmd); 562 | break; 563 | } 564 | } 565 | } 566 | -------------------------------------------------------------------------------- /Processing/Esplora/Esplora_Processing.py: -------------------------------------------------------------------------------- 1 | """ 2 | Interface to Esplora hardware for Processing.py examples. 3 | """ 4 | class Esplora: 5 | _port = {} 6 | 7 | @staticmethod 8 | def open(serports, index=-1): 9 | if index < 0: 10 | portName = serports.list()[len(serports.list()) + index] # Pick from last serial port in list 11 | else: 12 | portName = serports.list()[index] # Pick from serial port in list 13 | Esplora._port = serports(this, portName, 57600) 14 | Esplora._port.clear() 15 | Esplora.sync(5000) 16 | 17 | @staticmethod 18 | def close(): 19 | Esplora._port.close() 20 | 21 | @staticmethod 22 | def readLine(timeout=1000): 23 | serstr = None 24 | while serstr == None: 25 | m = millis() 26 | while Esplora._port.available() == 0: 27 | if (millis() - m) > timeout: 28 | return "" 29 | serstr = Esplora._port.readStringUntil(10) 30 | return serstr.strip() 31 | 32 | @staticmethod 33 | def sync(timeout=1000): 34 | Esplora._port.write("!\n") 35 | serstr = None 36 | while serstr != "!": 37 | m = millis() 38 | while Esplora._port.available() == 0: 39 | if (millis() - m) > timeout: 40 | return 41 | serstr = Esplora.readLine(10) 42 | 43 | @staticmethod 44 | def readDigital(pin): 45 | Esplora._port.write("=D%d\n" % pin) 46 | return int(Esplora.readLine()) 47 | 48 | @staticmethod 49 | def readAnalog(pin): 50 | Esplora._port.write("=A%d\n" % pin) 51 | return int(Esplora.readLine()) 52 | 53 | @staticmethod 54 | def writeDigital(pin, value): 55 | if value: 56 | value = 255 57 | Esplora._port.write("D%d=%d\n" % (pin, value)) 58 | 59 | @staticmethod 60 | def writePwm(pin, value): 61 | Esplora._port.write("D%d~%d\n" % (pin, value)) 62 | 63 | @staticmethod 64 | def writeLED(red, green = -1, blue = -1): 65 | if green < 0: 66 | green = red 67 | if blue < 0: 68 | blue = red 69 | Esplora._port.write("L=%d,%d,%d\n" % (red, green, blue)) 70 | 71 | @staticmethod 72 | def writeBuzzer(hertz = 0, duration = -1): 73 | if duration < 0: 74 | Esplora._port.write("T=%d\n" % hertz) 75 | else: 76 | Esplora._port.write("T=%d,%d\n" % (hertz, duration)) 77 | 78 | @staticmethod 79 | def readJoystick(): 80 | Esplora._port.write("=J\n") 81 | instr = Esplora.readLine().split(',') 82 | return [-int(instr[0]), int(instr[1])] 83 | 84 | @staticmethod 85 | def readAccelerometer(): 86 | Esplora._port.write("=X\n") 87 | instr = Esplora.readLine().split(',') 88 | return [int(instr[0]), int(instr[1]), int(instr[2])] 89 | 90 | @staticmethod 91 | def readButtons(): 92 | Esplora._port.write("=B\n") 93 | instr = Esplora.readLine().split(',') 94 | return [int(instr[0]), int(instr[1]), int(instr[2]), int(instr[3]), int(instr[4])] 95 | 96 | @staticmethod 97 | def readSlider(): 98 | Esplora._port.write("=S\n") 99 | return int(Esplora.readLine()) 100 | 101 | @staticmethod 102 | def readLightSensor(): 103 | Esplora._port.write("=L\n") 104 | return int(Esplora.readLine()) 105 | 106 | @staticmethod 107 | def readMicrophone(): 108 | Esplora._port.write("=M\n") 109 | return int(Esplora.readLine()) 110 | 111 | @staticmethod 112 | def readTempC(): 113 | Esplora._port.write("=C\n") 114 | return int(Esplora.readLine()) 115 | 116 | @staticmethod 117 | def readTempF(): 118 | Esplora._port.write("=F\n") 119 | return int(Esplora.readLine()) 120 | 121 | @staticmethod 122 | def tftSize(): 123 | Esplora._port.write("=Z\n") 124 | instr = Esplora._port.readline().rstrip().split(",") 125 | return [int(instr[0]), int(instr[1])] 126 | 127 | @staticmethod 128 | def tftBackground(red, green = -1, blue = -1): 129 | if green < 0: 130 | green = red 131 | if blue < 0: 132 | blue = red 133 | Esplora._port.write("SB=%d,%d,%d\n" % (red, green, blue)) 134 | Esplora.sync() 135 | 136 | @staticmethod 137 | def tftFill(red, green = -1, blue = -1): 138 | if green < 0: 139 | green = red 140 | if blue < 0: 141 | blue = red 142 | Esplora._port.write("SF=%d,%d,%d\n" % (red, green, blue)) 143 | Esplora.sync() 144 | 145 | @staticmethod 146 | def tftStroke(red, green = -1, blue = -1): 147 | if green < 0: 148 | green = red 149 | if blue < 0: 150 | blue = red 151 | Esplora._port.write("SS=%d,%d,%d\n" % (red, green, blue)) 152 | Esplora.sync() 153 | 154 | @staticmethod 155 | def tftNoFill(): 156 | Esplora._port.write("SNF\n") 157 | Esplora.sync() 158 | 159 | @staticmethod 160 | def tftNoStroke(): 161 | Esplora._port.write("SNS\n") 162 | Esplora.sync() 163 | 164 | @staticmethod 165 | def tftRect(xpos, ypos, width, height): 166 | Esplora._port.write("SR=%d,%d,%d,%d\n" % (xpos, ypos, width, height)) 167 | Esplora.sync() 168 | 169 | @staticmethod 170 | def tftLine(x1, y1, x2, y2): 171 | Esplora._port.write("SL=%d,%d,%d,%d\n" % (x1, y1, x2, y2)) 172 | Esplora.sync() 173 | 174 | @staticmethod 175 | def tftCircle(xpos, ypos, radius): 176 | Esplora._port.write("SC=%d,%d,%d\n" % (xpos, ypos, radius)) 177 | Esplora.sync() 178 | 179 | @staticmethod 180 | def tftText(string, xpos, ypos): 181 | Esplora._port.write('ST="%s",%d,%d\n' % (string, xpos, ypos)) 182 | Esplora.sync() 183 | 184 | @staticmethod 185 | def tftTextSize(size): 186 | Esplora._port.write('SZ=%d\n' % (size)) 187 | Esplora.sync() 188 | -------------------------------------------------------------------------------- /Processing/Esplora/ex0/Esplora_Processing$py.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dschmenk/Arduino/035fa38169dec00bfe0aa5b09154b9ad85452e01/Processing/Esplora/ex0/Esplora_Processing$py.class -------------------------------------------------------------------------------- /Processing/Esplora/ex0/Esplora_Processing.py: -------------------------------------------------------------------------------- 1 | class Esplora: 2 | _port = {} 3 | 4 | @staticmethod 5 | def open(serports, index=-1): 6 | if index < 0: 7 | portName = serports.list()[len(serports.list()) + index] # Pick from last serial port in list 8 | else: 9 | portName = serports.list()[index] # Pick from serial port in list 10 | Esplora._port = serports(this, portName, 57600) 11 | Esplora._port.clear() 12 | Esplora.sync(5000) 13 | 14 | @staticmethod 15 | def close(): 16 | Esplora._port.close() 17 | 18 | @staticmethod 19 | def readLine(timeout=1000): 20 | serstr = None 21 | while serstr == None: 22 | m = millis() 23 | while Esplora._port.available() == 0: 24 | if (millis() - m) > timeout: 25 | return "" 26 | serstr = Esplora._port.readStringUntil(10) 27 | return serstr.strip() 28 | 29 | @staticmethod 30 | def sync(timeout=1000): 31 | Esplora._port.write("!\n") 32 | serstr = None 33 | while serstr != "!": 34 | m = millis() 35 | while Esplora._port.available() == 0: 36 | if (millis() - m) > timeout: 37 | return 38 | serstr = Esplora.readLine(10) 39 | 40 | @staticmethod 41 | def readDigital(pin): 42 | Esplora._port.write("=D%d\n" % pin) 43 | return int(Esplora.readLine()) 44 | 45 | @staticmethod 46 | def readAnalog(pin): 47 | Esplora._port.write("=A%d\n" % pin) 48 | return int(Esplora.readLine()) 49 | 50 | @staticmethod 51 | def writeDigital(pin, value): 52 | if value: 53 | value = 255 54 | Esplora._port.write("D%d=%d\n" % (pin, value)) 55 | 56 | @staticmethod 57 | def writePwm(pin, value): 58 | Esplora._port.write("D%d~%d\n" % (pin, value)) 59 | 60 | @staticmethod 61 | def writeLED(red, green = -1, blue = -1): 62 | if green < 0: 63 | green = red 64 | if blue < 0: 65 | blue = red 66 | Esplora._port.write("L=%d,%d,%d\n" % (red, green, blue)) 67 | 68 | @staticmethod 69 | def writeBuzzer(hertz = 0, duration = -1): 70 | if duration < 0: 71 | Esplora._port.write("T=%d\n" % hertz) 72 | else: 73 | Esplora._port.write("T=%d,%d\n" % (hertz, duration)) 74 | 75 | @staticmethod 76 | def readJoystick(): 77 | Esplora._port.write("=J\n") 78 | instr = Esplora.readLine().split(',') 79 | return [-int(instr[0]), int(instr[1])] 80 | 81 | @staticmethod 82 | def readAccelerometer(): 83 | Esplora._port.write("=X\n") 84 | instr = Esplora.readLine().split(',') 85 | return [int(instr[0]), int(instr[1]), int(instr[2])] 86 | 87 | @staticmethod 88 | def readButtons(): 89 | Esplora._port.write("=B\n") 90 | instr = Esplora.readLine().split(',') 91 | return [int(instr[0]), int(instr[1]), int(instr[2]), int(instr[3]), int(instr[4])] 92 | 93 | @staticmethod 94 | def readSlider(): 95 | Esplora._port.write("=S\n") 96 | return int(Esplora.readLine()) 97 | 98 | @staticmethod 99 | def readLightSensor(): 100 | Esplora._port.write("=L\n") 101 | return int(Esplora.readLine()) 102 | 103 | @staticmethod 104 | def readMicrophone(): 105 | Esplora._port.write("=M\n") 106 | return int(Esplora.readLine()) 107 | 108 | @staticmethod 109 | def readTempC(): 110 | Esplora._port.write("=C\n") 111 | return int(Esplora.readLine()) 112 | 113 | @staticmethod 114 | def readTempF(): 115 | Esplora._port.write("=F\n") 116 | return int(Esplora.readLine()) 117 | 118 | @staticmethod 119 | def tftSize(): 120 | Esplora._port.write("=Z\n") 121 | instr = Esplora._port.readline().rstrip().split(",") 122 | return [int(instr[0]), int(instr[1])] 123 | 124 | @staticmethod 125 | def tftBackground(red, green = -1, blue = -1): 126 | if green < 0: 127 | green = red 128 | if blue < 0: 129 | blue = red 130 | Esplora._port.write("SB=%d,%d,%d\n" % (red, green, blue)) 131 | Esplora.sync() 132 | 133 | @staticmethod 134 | def tftFill(red, green = -1, blue = -1): 135 | if green < 0: 136 | green = red 137 | if blue < 0: 138 | blue = red 139 | Esplora._port.write("SF=%d,%d,%d\n" % (red, green, blue)) 140 | Esplora.sync() 141 | 142 | @staticmethod 143 | def tftStroke(red, green = -1, blue = -1): 144 | if green < 0: 145 | green = red 146 | if blue < 0: 147 | blue = red 148 | Esplora._port.write("SS=%d,%d,%d\n" % (red, green, blue)) 149 | Esplora.sync() 150 | 151 | @staticmethod 152 | def tftNoFill(): 153 | Esplora._port.write("SNF\n") 154 | Esplora.sync() 155 | 156 | @staticmethod 157 | def tftNoStroke(): 158 | Esplora._port.write("SNS\n") 159 | Esplora.sync() 160 | 161 | @staticmethod 162 | def tftRect(xpos, ypos, width, height): 163 | Esplora._port.write("SR=%d,%d,%d,%d\n" % (xpos, ypos, width, height)) 164 | Esplora.sync() 165 | 166 | @staticmethod 167 | def tftLine(x1, y1, x2, y2): 168 | Esplora._port.write("SL=%d,%d,%d,%d\n" % (x1, y1, x2, y2)) 169 | Esplora.sync() 170 | 171 | @staticmethod 172 | def tftCircle(xpos, ypos, radius): 173 | Esplora._port.write("SC=%d,%d,%d\n" % (xpos, ypos, radius)) 174 | Esplora.sync() 175 | 176 | @staticmethod 177 | def tftText(string, xpos, ypos): 178 | Esplora._port.write('ST="%s",%d,%d\n' % (string, xpos, ypos)) 179 | Esplora.sync() 180 | 181 | @staticmethod 182 | def tftTextSize(size): 183 | Esplora._port.write('SZ=%d\n' % (size)) 184 | Esplora.sync() 185 | -------------------------------------------------------------------------------- /Processing/Esplora/ex0/ex0.pyde: -------------------------------------------------------------------------------- 1 | """ 2 | Simple demo to connect to Esplora and interact with slider. 3 | """ 4 | add_library('serial') 5 | from Esplora_Processing import Esplora 6 | 7 | def setup(): 8 | Esplora.open(Serial) 9 | size(400,300) 10 | 11 | def draw(): 12 | slider = map(Esplora.readSlider(), 1023, 0, 0, 255) 13 | background(slider) 14 | text("Hello", 0, 10) 15 | Esplora.writeLED(slider) 16 | 17 | -------------------------------------------------------------------------------- /Processing/Esplora/ex0/sketch.properties: -------------------------------------------------------------------------------- 1 | mode.id=jycessing.mode.PythonMode 2 | mode=Python 3 | -------------------------------------------------------------------------------- /Processing/Esplora/ex1/ex1.pyde: -------------------------------------------------------------------------------- 1 | """ 2 | PONG! Demo - draw the ball 3 | """ 4 | xBall = 50 5 | yBall = 10 6 | sizeBall = 6 7 | 8 | def setup(): 9 | size(300,200) # set size of window 10 | 11 | def updateBall(colorBall): 12 | global xBall, yBall 13 | # Draw ball 14 | fill(colorBall) 15 | rect(xBall, yBall, sizeBall, sizeBall) 16 | 17 | def draw(): 18 | background(0) 19 | updateBall(255) 20 | -------------------------------------------------------------------------------- /Processing/Esplora/ex1/sketch.properties: -------------------------------------------------------------------------------- 1 | mode.id=jycessing.mode.PythonMode 2 | mode=Python 3 | -------------------------------------------------------------------------------- /Processing/Esplora/ex2/ex2.pyde: -------------------------------------------------------------------------------- 1 | """ 2 | PONG! Demo - bounce the ball 3 | """ 4 | xBall = 50 5 | yBall = 10 6 | sizeBall = 6 7 | xMove = 1 8 | yMove = 1 9 | 10 | def setup(): 11 | size(300,200) # set size of window 12 | 13 | def updateBall(colorBall): 14 | global xBall, yBall, xMove, yMove 15 | # Update ball position 16 | xBall = xBall + xMove 17 | yBall = yBall + yMove 18 | # Draw ball 19 | fill(colorBall) 20 | rect(xBall, yBall, sizeBall, sizeBall) 21 | # Bounce ball 22 | if xBall > width - sizeBall or xBall < 0: 23 | xMove = -xMove # Bounce off walls 24 | if yBall < 0: 25 | yMove = -yMove # Bounce off ceiling 26 | if yBall > height - sizeBall: 27 | yMove = -yMove # Bounce off floor 28 | 29 | def draw(): 30 | background(0) 31 | updateBall(255) 32 | -------------------------------------------------------------------------------- /Processing/Esplora/ex2/sketch.properties: -------------------------------------------------------------------------------- 1 | mode.id=jycessing.mode.PythonMode 2 | mode=Python 3 | -------------------------------------------------------------------------------- /Processing/Esplora/ex3/Esplora_Processing$py.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dschmenk/Arduino/035fa38169dec00bfe0aa5b09154b9ad85452e01/Processing/Esplora/ex3/Esplora_Processing$py.class -------------------------------------------------------------------------------- /Processing/Esplora/ex3/Esplora_Processing.py: -------------------------------------------------------------------------------- 1 | class Esplora: 2 | _port = {} 3 | 4 | @staticmethod 5 | def open(serports, index=-1): 6 | if index < 0: 7 | portName = serports.list()[len(serports.list()) + index] # Pick from last serial port in list 8 | else: 9 | portName = serports.list()[index] # Pick from serial port in list 10 | Esplora._port = serports(this, portName, 57600) 11 | Esplora._port.clear() 12 | Esplora.sync(5000) 13 | 14 | @staticmethod 15 | def close(): 16 | Esplora._port.close() 17 | 18 | @staticmethod 19 | def readLine(timeout=1000): 20 | serstr = None 21 | while serstr == None: 22 | m = millis() 23 | while Esplora._port.available() == 0: 24 | if (millis() - m) > timeout: 25 | return "" 26 | serstr = Esplora._port.readStringUntil(10) 27 | return serstr.strip() 28 | 29 | @staticmethod 30 | def sync(timeout=1000): 31 | Esplora._port.write("!\n") 32 | serstr = None 33 | while serstr != "!": 34 | m = millis() 35 | while Esplora._port.available() == 0: 36 | if (millis() - m) > timeout: 37 | return 38 | serstr = Esplora.readLine(10) 39 | 40 | @staticmethod 41 | def readDigital(pin): 42 | Esplora._port.write("=D%d\n" % pin) 43 | return int(Esplora.readLine()) 44 | 45 | @staticmethod 46 | def readAnalog(pin): 47 | Esplora._port.write("=A%d\n" % pin) 48 | return int(Esplora.readLine()) 49 | 50 | @staticmethod 51 | def writeDigital(pin, value): 52 | if value: 53 | value = 255 54 | Esplora._port.write("D%d=%d\n" % (pin, value)) 55 | 56 | @staticmethod 57 | def writePwm(pin, value): 58 | Esplora._port.write("D%d~%d\n" % (pin, value)) 59 | 60 | @staticmethod 61 | def writeRGB(red, green = -1, blue = -1): 62 | if green < 0: 63 | green = red 64 | if blue < 0: 65 | blue = red 66 | Esplora._port.write("L=%d,%d,%d\n" % (red, green, blue)) 67 | 68 | @staticmethod 69 | def writeBuzzer(hertz = 0, duration = -1): 70 | if duration < 0: 71 | Esplora._port.write("T=%d\n" % hertz) 72 | else: 73 | Esplora._port.write("T=%d,%d\n" % (hertz, duration)) 74 | 75 | @staticmethod 76 | def readJoystick(): 77 | Esplora._port.write("=J\n") 78 | instr = Esplora.readLine().split(',') 79 | return [-int(instr[0]), int(instr[1])] 80 | 81 | @staticmethod 82 | def readAccelerometer(): 83 | Esplora._port.write("=X\n") 84 | instr = Esplora.readLine().split(',') 85 | return [int(instr[0]), int(instr[1]), int(instr[2])] 86 | 87 | @staticmethod 88 | def readButtons(): 89 | Esplora._port.write("=B\n") 90 | instr = Esplora.readLine().split(',') 91 | return [int(instr[0]), int(instr[1]), int(instr[2]), int(instr[3]), int(instr[4])] 92 | 93 | @staticmethod 94 | def readSlider(): 95 | Esplora._port.write("=S\n") 96 | return int(Esplora.readLine()) 97 | 98 | @staticmethod 99 | def readLightSensor(): 100 | Esplora._port.write("=L\n") 101 | return int(Esplora.readLine()) 102 | 103 | @staticmethod 104 | def readMicrophone(): 105 | Esplora._port.write("=M\n") 106 | return int(Esplora.readLine()) 107 | 108 | @staticmethod 109 | def readTempC(): 110 | Esplora._port.write("=C\n") 111 | return int(Esplora.readLine()) 112 | 113 | @staticmethod 114 | def readTempF(): 115 | Esplora._port.write("=F\n") 116 | return int(Esplora.readLine()) 117 | 118 | @staticmethod 119 | def tftSize(): 120 | Esplora._port.write("=Z\n") 121 | instr = Esplora._port.readline().rstrip().split(",") 122 | return [int(instr[0]), int(instr[1])] 123 | 124 | @staticmethod 125 | def tftBackground(red, green = -1, blue = -1): 126 | if green < 0: 127 | green = red 128 | if blue < 0: 129 | blue = red 130 | Esplora._port.write("SB=%d,%d,%d\n" % (red, green, blue)) 131 | Esplora.sync() 132 | 133 | @staticmethod 134 | def tftFill(red, green = -1, blue = -1): 135 | if green < 0: 136 | green = red 137 | if blue < 0: 138 | blue = red 139 | Esplora._port.write("SF=%d,%d,%d\n" % (red, green, blue)) 140 | Esplora.sync() 141 | 142 | @staticmethod 143 | def tftStroke(red, green = -1, blue = -1): 144 | if green < 0: 145 | green = red 146 | if blue < 0: 147 | blue = red 148 | Esplora._port.write("SS=%d,%d,%d\n" % (red, green, blue)) 149 | Esplora.sync() 150 | 151 | @staticmethod 152 | def tftNoFill(): 153 | Esplora._port.write("SNF\n") 154 | Esplora.sync() 155 | 156 | @staticmethod 157 | def tftNoStroke(): 158 | Esplora._port.write("SNS\n") 159 | Esplora.sync() 160 | 161 | @staticmethod 162 | def tftRect(xpos, ypos, width, height): 163 | Esplora._port.write("SR=%d,%d,%d,%d\n" % (xpos, ypos, width, height)) 164 | Esplora.sync() 165 | 166 | @staticmethod 167 | def tftLine(x1, y1, x2, y2): 168 | Esplora._port.write("SL=%d,%d,%d,%d\n" % (x1, y1, x2, y2)) 169 | Esplora.sync() 170 | 171 | @staticmethod 172 | def tftCircle(xpos, ypos, radius): 173 | Esplora._port.write("SC=%d,%d,%d\n" % (xpos, ypos, radius)) 174 | Esplora.sync() 175 | 176 | @staticmethod 177 | def tftText(string, xpos, ypos): 178 | Esplora._port.write('ST="%s",%d,%d\n' % (string, xpos, ypos)) 179 | Esplora.sync() 180 | 181 | @staticmethod 182 | def tftTextSize(size): 183 | Esplora._port.write('SZ=%d\n' % (size)) 184 | Esplora.sync() 185 | -------------------------------------------------------------------------------- /Processing/Esplora/ex3/ex3.pyde: -------------------------------------------------------------------------------- 1 | """ 2 | PONG! Demo - integrate paddle control with Esplora slider 3 | """ 4 | add_library('serial') 5 | from Esplora_Processing import Esplora 6 | 7 | xBall = 50 8 | yBall = 10 9 | sizeBall = 6 10 | xMove = 1 11 | yMove = 1 12 | paddle = 0 13 | widthPaddle = 30 14 | heightPaddle = 6 15 | 16 | def setup(): 17 | size(300,200) # set size of window 18 | Esplora.open(Serial) 19 | 20 | def updatePaddle(colorPaddle): 21 | global paddle 22 | # Update paddle position 23 | paddle = map(Esplora.readSlider(), 1023, 0, 0, width - widthPaddle) 24 | fill(colorPaddle) 25 | rect(paddle, height - heightPaddle, widthPaddle, heightPaddle) 26 | 27 | def updateBall(colorBall): 28 | global xBall, yBall, xMove, yMove 29 | # Update ball position 30 | xBall = xBall + xMove 31 | yBall = yBall + yMove 32 | fill(colorBall) 33 | rect(xBall, yBall, sizeBall, sizeBall) 34 | # Bounce ball 35 | if xBall > width - sizeBall or xBall < 0: 36 | xMove = -xMove # Bounce off walls 37 | if yBall < 0: 38 | yMove = -yMove # Bounce off top 39 | if yBall > height - heightPaddle - sizeBall: 40 | # Check if ball hit paddle or game over 41 | if xBall + sizeBall >= paddle and xBall <= paddle + widthPaddle: 42 | yMove = -yMove # Bounce off paddle 43 | else: 44 | exit() # Missed ball - game over 45 | 46 | def draw(): 47 | background(0) 48 | updatePaddle(128) 49 | updateBall(255) 50 | -------------------------------------------------------------------------------- /Processing/Esplora/ex3/sketch.properties: -------------------------------------------------------------------------------- 1 | mode.id=jycessing.mode.PythonMode 2 | mode=Python 3 | -------------------------------------------------------------------------------- /Processing/Esplora/ex4/Esplora_Processing$py.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dschmenk/Arduino/035fa38169dec00bfe0aa5b09154b9ad85452e01/Processing/Esplora/ex4/Esplora_Processing$py.class -------------------------------------------------------------------------------- /Processing/Esplora/ex4/Esplora_Processing.py: -------------------------------------------------------------------------------- 1 | class Esplora: 2 | _port = {} 3 | 4 | @staticmethod 5 | def open(serports, index=-1): 6 | if index < 0: 7 | portName = serports.list()[len(serports.list()) + index] # Pick from last serial port in list 8 | else: 9 | portName = serports.list()[index] # Pick from serial port in list 10 | Esplora._port = serports(this, portName, 57600) 11 | Esplora._port.clear() 12 | Esplora.sync(5000) 13 | 14 | @staticmethod 15 | def close(): 16 | Esplora._port.close() 17 | 18 | @staticmethod 19 | def readLine(timeout=1000): 20 | serstr = None 21 | while serstr == None: 22 | m = millis() 23 | while Esplora._port.available() == 0: 24 | if (millis() - m) > timeout: 25 | return "" 26 | serstr = Esplora._port.readStringUntil(10) 27 | return serstr.strip() 28 | 29 | @staticmethod 30 | def sync(timeout=1000): 31 | Esplora._port.write("!\n") 32 | serstr = None 33 | while serstr != "!": 34 | m = millis() 35 | while Esplora._port.available() == 0: 36 | if (millis() - m) > timeout: 37 | return 38 | serstr = Esplora.readLine(10) 39 | 40 | @staticmethod 41 | def readDigital(pin): 42 | Esplora._port.write("=D%d\n" % pin) 43 | return int(Esplora.readLine()) 44 | 45 | @staticmethod 46 | def readAnalog(pin): 47 | Esplora._port.write("=A%d\n" % pin) 48 | return int(Esplora.readLine()) 49 | 50 | @staticmethod 51 | def writeDigital(pin, value): 52 | if value: 53 | value = 255 54 | Esplora._port.write("D%d=%d\n" % (pin, value)) 55 | 56 | @staticmethod 57 | def writePwm(pin, value): 58 | Esplora._port.write("D%d~%d\n" % (pin, value)) 59 | 60 | @staticmethod 61 | def writeRGB(red, green = -1, blue = -1): 62 | if green < 0: 63 | green = red 64 | if blue < 0: 65 | blue = red 66 | Esplora._port.write("L=%d,%d,%d\n" % (red, green, blue)) 67 | 68 | @staticmethod 69 | def writeBuzzer(hertz = 0, duration = -1): 70 | if duration < 0: 71 | Esplora._port.write("T=%d\n" % hertz) 72 | else: 73 | Esplora._port.write("T=%d,%d\n" % (hertz, duration)) 74 | 75 | @staticmethod 76 | def readJoystick(): 77 | Esplora._port.write("=J\n") 78 | instr = Esplora.readLine().split(',') 79 | return [-int(instr[0]), int(instr[1])] 80 | 81 | @staticmethod 82 | def readAccelerometer(): 83 | Esplora._port.write("=X\n") 84 | instr = Esplora.readLine().split(',') 85 | return [int(instr[0]), int(instr[1]), int(instr[2])] 86 | 87 | @staticmethod 88 | def readButtons(): 89 | Esplora._port.write("=B\n") 90 | instr = Esplora.readLine().split(',') 91 | return [int(instr[0]), int(instr[1]), int(instr[2]), int(instr[3]), int(instr[4])] 92 | 93 | @staticmethod 94 | def readSlider(): 95 | Esplora._port.write("=S\n") 96 | return int(Esplora.readLine()) 97 | 98 | @staticmethod 99 | def readLightSensor(): 100 | Esplora._port.write("=L\n") 101 | return int(Esplora.readLine()) 102 | 103 | @staticmethod 104 | def readMicrophone(): 105 | Esplora._port.write("=M\n") 106 | return int(Esplora.readLine()) 107 | 108 | @staticmethod 109 | def readTempC(): 110 | Esplora._port.write("=C\n") 111 | return int(Esplora.readLine()) 112 | 113 | @staticmethod 114 | def readTempF(): 115 | Esplora._port.write("=F\n") 116 | return int(Esplora.readLine()) 117 | 118 | @staticmethod 119 | def tftSize(): 120 | Esplora._port.write("=Z\n") 121 | instr = Esplora._port.readline().rstrip().split(",") 122 | return [int(instr[0]), int(instr[1])] 123 | 124 | @staticmethod 125 | def tftBackground(red, green = -1, blue = -1): 126 | if green < 0: 127 | green = red 128 | if blue < 0: 129 | blue = red 130 | Esplora._port.write("SB=%d,%d,%d\n" % (red, green, blue)) 131 | Esplora.sync() 132 | 133 | @staticmethod 134 | def tftFill(red, green = -1, blue = -1): 135 | if green < 0: 136 | green = red 137 | if blue < 0: 138 | blue = red 139 | Esplora._port.write("SF=%d,%d,%d\n" % (red, green, blue)) 140 | Esplora.sync() 141 | 142 | @staticmethod 143 | def tftStroke(red, green = -1, blue = -1): 144 | if green < 0: 145 | green = red 146 | if blue < 0: 147 | blue = red 148 | Esplora._port.write("SS=%d,%d,%d\n" % (red, green, blue)) 149 | Esplora.sync() 150 | 151 | @staticmethod 152 | def tftNoFill(): 153 | Esplora._port.write("SNF\n") 154 | Esplora.sync() 155 | 156 | @staticmethod 157 | def tftNoStroke(): 158 | Esplora._port.write("SNS\n") 159 | Esplora.sync() 160 | 161 | @staticmethod 162 | def tftRect(xpos, ypos, width, height): 163 | Esplora._port.write("SR=%d,%d,%d,%d\n" % (xpos, ypos, width, height)) 164 | Esplora.sync() 165 | 166 | @staticmethod 167 | def tftLine(x1, y1, x2, y2): 168 | Esplora._port.write("SL=%d,%d,%d,%d\n" % (x1, y1, x2, y2)) 169 | Esplora.sync() 170 | 171 | @staticmethod 172 | def tftCircle(xpos, ypos, radius): 173 | Esplora._port.write("SC=%d,%d,%d\n" % (xpos, ypos, radius)) 174 | Esplora.sync() 175 | 176 | @staticmethod 177 | def tftText(string, xpos, ypos): 178 | Esplora._port.write('ST="%s",%d,%d\n' % (string, xpos, ypos)) 179 | Esplora.sync() 180 | 181 | @staticmethod 182 | def tftTextSize(size): 183 | Esplora._port.write('SZ=%d\n' % (size)) 184 | Esplora.sync() 185 | -------------------------------------------------------------------------------- /Processing/Esplora/ex4/ex4.pyde: -------------------------------------------------------------------------------- 1 | """ 2 | PONG! Demo - bounce sound using Esplora buzzer 3 | """ 4 | add_library('serial') 5 | from Esplora_Processing import Esplora 6 | 7 | xBall = 50 8 | yBall = 10 9 | sizeBall = 6 10 | xMove = 1 11 | yMove = 1 12 | paddle = 0 13 | widthPaddle = 30 14 | heightPaddle = 6 15 | 16 | def setup(): 17 | size(300,200) # set size of window 18 | Esplora.open(Serial) 19 | 20 | def updatePaddle(colorPaddle): 21 | global paddle 22 | # Update paddle position 23 | paddle = map(Esplora.readSlider(), 1023, 0, 0, width - widthPaddle) 24 | fill(colorPaddle) 25 | rect(paddle, height - heightPaddle, widthPaddle, heightPaddle) 26 | 27 | def updateBall(colorBall): 28 | global xBall, yBall, xMove, yMove 29 | # Update ball position 30 | xBall = xBall + xMove 31 | yBall = yBall + yMove 32 | fill(colorBall) 33 | rect(xBall, yBall, sizeBall, sizeBall) 34 | # Bounce ball 35 | if xBall > width - sizeBall or xBall < 0: 36 | xMove = -xMove # Bounce off walls 37 | Esplora.writeBuzzer(1000, 10) 38 | if yBall < 0: 39 | yMove = -yMove # Bounce off top 40 | Esplora.writeBuzzer(1000, 10) 41 | if yBall > height - heightPaddle - sizeBall: 42 | # Check if ball hit paddle or game over 43 | if xBall + sizeBall >= paddle and xBall <= paddle + widthPaddle: 44 | yMove = -yMove # Bounce off paddle 45 | Esplora.writeBuzzer(2000, 10) 46 | else: 47 | Esplora.writeBuzzer(200, 500) 48 | exit() # Missed ball - game over 49 | 50 | def draw(): 51 | background(0) 52 | updatePaddle(128) 53 | updateBall(255) 54 | -------------------------------------------------------------------------------- /Processing/Esplora/ex4/sketch.properties: -------------------------------------------------------------------------------- 1 | mode.id=jycessing.mode.PythonMode 2 | mode=Python 3 | -------------------------------------------------------------------------------- /Processing/Esplora/ex5/Esplora_Processing$py.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dschmenk/Arduino/035fa38169dec00bfe0aa5b09154b9ad85452e01/Processing/Esplora/ex5/Esplora_Processing$py.class -------------------------------------------------------------------------------- /Processing/Esplora/ex5/Esplora_Processing.py: -------------------------------------------------------------------------------- 1 | class Esplora: 2 | _port = {} 3 | 4 | @staticmethod 5 | def open(serports, index=-1): 6 | if index < 0: 7 | portName = serports.list()[len(serports.list()) + index] # Pick from last serial port in list 8 | else: 9 | portName = serports.list()[index] # Pick from serial port in list 10 | Esplora._port = serports(this, portName, 57600) 11 | Esplora._port.clear() 12 | Esplora.sync(5000) 13 | 14 | @staticmethod 15 | def close(): 16 | Esplora._port.close() 17 | 18 | @staticmethod 19 | def readLine(timeout=1000): 20 | serstr = None 21 | while serstr == None: 22 | m = millis() 23 | while Esplora._port.available() == 0: 24 | if (millis() - m) > timeout: 25 | return "" 26 | serstr = Esplora._port.readStringUntil(10) 27 | return serstr.strip() 28 | 29 | @staticmethod 30 | def sync(timeout=1000): 31 | Esplora._port.write("!\n") 32 | serstr = None 33 | while serstr != "!": 34 | m = millis() 35 | while Esplora._port.available() == 0: 36 | if (millis() - m) > timeout: 37 | return 38 | serstr = Esplora.readLine(10) 39 | 40 | @staticmethod 41 | def readDigital(pin): 42 | Esplora._port.write("=D%d\n" % pin) 43 | return int(Esplora.readLine()) 44 | 45 | @staticmethod 46 | def readAnalog(pin): 47 | Esplora._port.write("=A%d\n" % pin) 48 | return int(Esplora.readLine()) 49 | 50 | @staticmethod 51 | def writeDigital(pin, value): 52 | if value: 53 | value = 255 54 | Esplora._port.write("D%d=%d\n" % (pin, value)) 55 | 56 | @staticmethod 57 | def writePwm(pin, value): 58 | Esplora._port.write("D%d~%d\n" % (pin, value)) 59 | 60 | @staticmethod 61 | def writeLED(red, green = -1, blue = -1): 62 | if green < 0: 63 | green = red 64 | if blue < 0: 65 | blue = red 66 | Esplora._port.write("L=%d,%d,%d\n" % (red, green, blue)) 67 | 68 | @staticmethod 69 | def writeBuzzer(hertz = 0, duration = -1): 70 | if duration < 0: 71 | Esplora._port.write("T=%d\n" % hertz) 72 | else: 73 | Esplora._port.write("T=%d,%d\n" % (hertz, duration)) 74 | 75 | @staticmethod 76 | def readJoystick(): 77 | Esplora._port.write("=J\n") 78 | instr = Esplora.readLine().split(',') 79 | return [-int(instr[0]), int(instr[1])] 80 | 81 | @staticmethod 82 | def readAccelerometer(): 83 | Esplora._port.write("=X\n") 84 | instr = Esplora.readLine().split(',') 85 | return [int(instr[0]), int(instr[1]), int(instr[2])] 86 | 87 | @staticmethod 88 | def readButtons(): 89 | Esplora._port.write("=B\n") 90 | instr = Esplora.readLine().split(',') 91 | return [int(instr[0]), int(instr[1]), int(instr[2]), int(instr[3]), int(instr[4])] 92 | 93 | @staticmethod 94 | def readSlider(): 95 | Esplora._port.write("=S\n") 96 | return int(Esplora.readLine()) 97 | 98 | @staticmethod 99 | def readLightSensor(): 100 | Esplora._port.write("=L\n") 101 | return int(Esplora.readLine()) 102 | 103 | @staticmethod 104 | def readMicrophone(): 105 | Esplora._port.write("=M\n") 106 | return int(Esplora.readLine()) 107 | 108 | @staticmethod 109 | def readTempC(): 110 | Esplora._port.write("=C\n") 111 | return int(Esplora.readLine()) 112 | 113 | @staticmethod 114 | def readTempF(): 115 | Esplora._port.write("=F\n") 116 | return int(Esplora.readLine()) 117 | 118 | @staticmethod 119 | def tftSize(): 120 | Esplora._port.write("=Z\n") 121 | instr = Esplora._port.readline().rstrip().split(",") 122 | return [int(instr[0]), int(instr[1])] 123 | 124 | @staticmethod 125 | def tftBackground(red, green = -1, blue = -1): 126 | if green < 0: 127 | green = red 128 | if blue < 0: 129 | blue = red 130 | Esplora._port.write("SB=%d,%d,%d\n" % (red, green, blue)) 131 | Esplora.sync() 132 | 133 | @staticmethod 134 | def tftFill(red, green = -1, blue = -1): 135 | if green < 0: 136 | green = red 137 | if blue < 0: 138 | blue = red 139 | Esplora._port.write("SF=%d,%d,%d\n" % (red, green, blue)) 140 | Esplora.sync() 141 | 142 | @staticmethod 143 | def tftStroke(red, green = -1, blue = -1): 144 | if green < 0: 145 | green = red 146 | if blue < 0: 147 | blue = red 148 | Esplora._port.write("SS=%d,%d,%d\n" % (red, green, blue)) 149 | Esplora.sync() 150 | 151 | @staticmethod 152 | def tftNoFill(): 153 | Esplora._port.write("SNF\n") 154 | Esplora.sync() 155 | 156 | @staticmethod 157 | def tftNoStroke(): 158 | Esplora._port.write("SNS\n") 159 | Esplora.sync() 160 | 161 | @staticmethod 162 | def tftRect(xpos, ypos, width, height): 163 | Esplora._port.write("SR=%d,%d,%d,%d\n" % (xpos, ypos, width, height)) 164 | Esplora.sync() 165 | 166 | @staticmethod 167 | def tftLine(x1, y1, x2, y2): 168 | Esplora._port.write("SL=%d,%d,%d,%d\n" % (x1, y1, x2, y2)) 169 | Esplora.sync() 170 | 171 | @staticmethod 172 | def tftCircle(xpos, ypos, radius): 173 | Esplora._port.write("SC=%d,%d,%d\n" % (xpos, ypos, radius)) 174 | Esplora.sync() 175 | 176 | @staticmethod 177 | def tftText(string, xpos, ypos): 178 | Esplora._port.write('ST="%s",%d,%d\n' % (string, xpos, ypos)) 179 | Esplora.sync() 180 | 181 | @staticmethod 182 | def tftTextSize(size): 183 | Esplora._port.write('SZ=%d\n' % (size)) 184 | Esplora.sync() 185 | -------------------------------------------------------------------------------- /Processing/Esplora/ex5/ex5.pyde: -------------------------------------------------------------------------------- 1 | """ 2 | Use Esplora accelerometer to draw a box in the window. 3 | The Esplora slider will adjust the size of the box. 4 | """ 5 | add_library('serial') 6 | from Esplora_Processing import Esplora 7 | 8 | xCal = 0 9 | yCal = 0 10 | zCal = 0 11 | 12 | def setup(): 13 | global xCal, yCal, zCal 14 | Esplora.open(Serial) 15 | size(255,255) 16 | xCal, yCal, zCal = Esplora.readAccelerometer() 17 | background(0) 18 | 19 | def draw(): 20 | xRaw, yRaw, zRaw = Esplora.readAccelerometer() 21 | x = map(xRaw - xCal, 127, -128, 0, 255) 22 | y = map(yRaw - yCal, 127, -128, 255, 0) 23 | z = map(zRaw - zCal, 127, -128, 0, 255) 24 | size = map(Esplora.readSlider(), 0, 1023, 31, 1) 25 | #bright = map(Esplora.readLightSensor(), 0, 255, 0, 255) 26 | stroke(z) 27 | fill(z) 28 | rect(x, y, size, size) 29 | 30 | -------------------------------------------------------------------------------- /Processing/Esplora/ex6/Esplora_Processing$py.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dschmenk/Arduino/035fa38169dec00bfe0aa5b09154b9ad85452e01/Processing/Esplora/ex6/Esplora_Processing$py.class -------------------------------------------------------------------------------- /Processing/Esplora/ex6/Esplora_Processing.py: -------------------------------------------------------------------------------- 1 | class Esplora: 2 | _port = {} 3 | 4 | @staticmethod 5 | def open(serports, index=-1): 6 | if index < 0: 7 | portName = serports.list()[len(serports.list()) + index] # Pick from last serial port in list 8 | else: 9 | portName = serports.list()[index] # Pick from serial port in list 10 | Esplora._port = serports(this, portName, 57600) 11 | Esplora._port.clear() 12 | Esplora.sync(5000) 13 | 14 | @staticmethod 15 | def close(): 16 | Esplora._port.close() 17 | 18 | @staticmethod 19 | def readLine(timeout=1000): 20 | serstr = None 21 | while serstr == None: 22 | m = millis() 23 | while Esplora._port.available() == 0: 24 | if (millis() - m) > timeout: 25 | return "" 26 | serstr = Esplora._port.readStringUntil(10) 27 | return serstr.strip() 28 | 29 | @staticmethod 30 | def sync(timeout=1000): 31 | Esplora._port.write("!\n") 32 | serstr = None 33 | while serstr != "!": 34 | m = millis() 35 | while Esplora._port.available() == 0: 36 | if (millis() - m) > timeout: 37 | return 38 | serstr = Esplora.readLine(10) 39 | 40 | @staticmethod 41 | def readDigital(pin): 42 | Esplora._port.write("=D%d\n" % pin) 43 | return int(Esplora.readLine()) 44 | 45 | @staticmethod 46 | def readAnalog(pin): 47 | Esplora._port.write("=A%d\n" % pin) 48 | return int(Esplora.readLine()) 49 | 50 | @staticmethod 51 | def writeDigital(pin, value): 52 | if value: 53 | value = 255 54 | Esplora._port.write("D%d=%d\n" % (pin, value)) 55 | 56 | @staticmethod 57 | def writePwm(pin, value): 58 | Esplora._port.write("D%d~%d\n" % (pin, value)) 59 | 60 | @staticmethod 61 | def writeLED(red, green = -1, blue = -1): 62 | if green < 0: 63 | green = red 64 | if blue < 0: 65 | blue = red 66 | Esplora._port.write("L=%d,%d,%d\n" % (red, green, blue)) 67 | 68 | @staticmethod 69 | def writeBuzzer(hertz = 0, duration = -1): 70 | if duration < 0: 71 | Esplora._port.write("T=%d\n" % hertz) 72 | else: 73 | Esplora._port.write("T=%d,%d\n" % (hertz, duration)) 74 | 75 | @staticmethod 76 | def readJoystick(): 77 | Esplora._port.write("=J\n") 78 | instr = Esplora.readLine().split(',') 79 | return [-int(instr[0]), int(instr[1])] 80 | 81 | @staticmethod 82 | def readAccelerometer(): 83 | Esplora._port.write("=X\n") 84 | instr = Esplora.readLine().split(',') 85 | return [int(instr[0]), int(instr[1]), int(instr[2])] 86 | 87 | @staticmethod 88 | def readButtons(): 89 | Esplora._port.write("=B\n") 90 | instr = Esplora.readLine().split(',') 91 | return [int(instr[0]), int(instr[1]), int(instr[2]), int(instr[3]), int(instr[4])] 92 | 93 | @staticmethod 94 | def readSlider(): 95 | Esplora._port.write("=S\n") 96 | return int(Esplora.readLine()) 97 | 98 | @staticmethod 99 | def readLightSensor(): 100 | Esplora._port.write("=L\n") 101 | return int(Esplora.readLine()) 102 | 103 | @staticmethod 104 | def readMicrophone(): 105 | Esplora._port.write("=M\n") 106 | return int(Esplora.readLine()) 107 | 108 | @staticmethod 109 | def readTempC(): 110 | Esplora._port.write("=C\n") 111 | return int(Esplora.readLine()) 112 | 113 | @staticmethod 114 | def readTempF(): 115 | Esplora._port.write("=F\n") 116 | return int(Esplora.readLine()) 117 | 118 | @staticmethod 119 | def tftSize(): 120 | Esplora._port.write("=Z\n") 121 | instr = Esplora._port.readline().rstrip().split(",") 122 | return [int(instr[0]), int(instr[1])] 123 | 124 | @staticmethod 125 | def tftBackground(red, green = -1, blue = -1): 126 | if green < 0: 127 | green = red 128 | if blue < 0: 129 | blue = red 130 | Esplora._port.write("SB=%d,%d,%d\n" % (red, green, blue)) 131 | Esplora.sync() 132 | 133 | @staticmethod 134 | def tftFill(red, green = -1, blue = -1): 135 | if green < 0: 136 | green = red 137 | if blue < 0: 138 | blue = red 139 | Esplora._port.write("SF=%d,%d,%d\n" % (red, green, blue)) 140 | Esplora.sync() 141 | 142 | @staticmethod 143 | def tftStroke(red, green = -1, blue = -1): 144 | if green < 0: 145 | green = red 146 | if blue < 0: 147 | blue = red 148 | Esplora._port.write("SS=%d,%d,%d\n" % (red, green, blue)) 149 | Esplora.sync() 150 | 151 | @staticmethod 152 | def tftNoFill(): 153 | Esplora._port.write("SNF\n") 154 | Esplora.sync() 155 | 156 | @staticmethod 157 | def tftNoStroke(): 158 | Esplora._port.write("SNS\n") 159 | Esplora.sync() 160 | 161 | @staticmethod 162 | def tftRect(xpos, ypos, width, height): 163 | Esplora._port.write("SR=%d,%d,%d,%d\n" % (xpos, ypos, width, height)) 164 | Esplora.sync() 165 | 166 | @staticmethod 167 | def tftLine(x1, y1, x2, y2): 168 | Esplora._port.write("SL=%d,%d,%d,%d\n" % (x1, y1, x2, y2)) 169 | Esplora.sync() 170 | 171 | @staticmethod 172 | def tftCircle(xpos, ypos, radius): 173 | Esplora._port.write("SC=%d,%d,%d\n" % (xpos, ypos, radius)) 174 | Esplora.sync() 175 | 176 | @staticmethod 177 | def tftText(string, xpos, ypos): 178 | Esplora._port.write('ST="%s",%d,%d\n' % (string, xpos, ypos)) 179 | Esplora.sync() 180 | 181 | @staticmethod 182 | def tftTextSize(size): 183 | Esplora._port.write('SZ=%d\n' % (size)) 184 | Esplora.sync() 185 | -------------------------------------------------------------------------------- /Processing/Esplora/ex6/ex6.pyde: -------------------------------------------------------------------------------- 1 | """ 2 | Use Esplora joystick to draw a box in the window. 3 | The Esplora slider will adjust the size of the box. 4 | The Esplora joystick button clears the window. 5 | The Esplora button 1 exits the demo,. 6 | """ 7 | add_library('serial') 8 | from Esplora_Processing import Esplora 9 | 10 | xCal = 0 11 | yCal = 0 12 | 13 | def setup(): 14 | global xCal, yCal 15 | Esplora.open(Serial) 16 | size(255,255) 17 | xCal, yCal = Esplora.readJoystick() 18 | background(0) 19 | 20 | def draw(): 21 | bttn0, bttn1, bttn2, bttn3, bttnJoy = Esplora.readButtons() 22 | if bttn0 == 0: 23 | exit() 24 | if bttnJoy == 0: 25 | background(0) 26 | size = map(Esplora.readSlider(), 0, 1023, 31, 1) 27 | bright = map(Esplora.readLightSensor(), 0, 255, 0, 255) 28 | stroke(bright) 29 | fill(bright) 30 | xRaw, yRaw = Esplora.readJoystick() 31 | x = map(xRaw - xCal, -512, 511, 0, 255) 32 | y = map(yRaw - yCal, -512, 511, 0, 255) 33 | if x < 0: 34 | x = 0 35 | if x > width - size: 36 | x = width - size 37 | if y < 0: 38 | y = 0 39 | if y > height - size: 40 | y = height - size 41 | rect(x, y, size, size) 42 | 43 | -------------------------------------------------------------------------------- /Processing/Esplora/ex6/sketch.properties: -------------------------------------------------------------------------------- 1 | mode.id=jycessing.mode.PythonMode 2 | mode=Python 3 | -------------------------------------------------------------------------------- /Processing/Esplora/ex7/Esplora_Processing$py.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dschmenk/Arduino/035fa38169dec00bfe0aa5b09154b9ad85452e01/Processing/Esplora/ex7/Esplora_Processing$py.class -------------------------------------------------------------------------------- /Processing/Esplora/ex7/Esplora_Processing.py: -------------------------------------------------------------------------------- 1 | """ 2 | Interface to Esplora hardware for Processing.py examples. 3 | """ 4 | class Esplora: 5 | _port = {} 6 | 7 | @staticmethod 8 | def open(serports, index=-1): 9 | if index < 0: 10 | portName = serports.list()[len(serports.list()) + index] # Pick from last serial port in list 11 | else: 12 | portName = serports.list()[index] # Pick from serial port in list 13 | Esplora._port = serports(this, portName, 57600) 14 | Esplora._port.clear() 15 | Esplora.sync(5000) 16 | 17 | @staticmethod 18 | def close(): 19 | Esplora._port.close() 20 | 21 | @staticmethod 22 | def readLine(timeout=1000): 23 | serstr = None 24 | while serstr == None: 25 | m = millis() 26 | while Esplora._port.available() == 0: 27 | if (millis() - m) > timeout: 28 | return "" 29 | serstr = Esplora._port.readStringUntil(10) 30 | return serstr.strip() 31 | 32 | @staticmethod 33 | def sync(timeout=1000): 34 | Esplora._port.write("!\n") 35 | serstr = None 36 | while serstr != "!": 37 | m = millis() 38 | while Esplora._port.available() == 0: 39 | if (millis() - m) > timeout: 40 | return 41 | serstr = Esplora.readLine(10) 42 | 43 | @staticmethod 44 | def readDigital(pin): 45 | Esplora._port.write("=D%d\n" % pin) 46 | return int(Esplora.readLine()) 47 | 48 | @staticmethod 49 | def readAnalog(pin): 50 | Esplora._port.write("=A%d\n" % pin) 51 | return int(Esplora.readLine()) 52 | 53 | @staticmethod 54 | def writeDigital(pin, value): 55 | if value: 56 | value = 255 57 | Esplora._port.write("D%d=%d\n" % (pin, value)) 58 | 59 | @staticmethod 60 | def writePwm(pin, value): 61 | Esplora._port.write("D%d~%d\n" % (pin, value)) 62 | 63 | @staticmethod 64 | def writeLED(red, green = -1, blue = -1): 65 | if green < 0: 66 | green = red 67 | if blue < 0: 68 | blue = red 69 | Esplora._port.write("L=%d,%d,%d\n" % (red, green, blue)) 70 | 71 | @staticmethod 72 | def writeBuzzer(hertz = 0, duration = -1): 73 | if duration < 0: 74 | Esplora._port.write("T=%d\n" % hertz) 75 | else: 76 | Esplora._port.write("T=%d,%d\n" % (hertz, duration)) 77 | 78 | @staticmethod 79 | def readJoystick(): 80 | Esplora._port.write("=J\n") 81 | instr = Esplora.readLine().split(',') 82 | return [-int(instr[0]), int(instr[1])] 83 | 84 | @staticmethod 85 | def readAccelerometer(): 86 | Esplora._port.write("=X\n") 87 | instr = Esplora.readLine().split(',') 88 | return [int(instr[0]), int(instr[1]), int(instr[2])] 89 | 90 | @staticmethod 91 | def readButtons(): 92 | Esplora._port.write("=B\n") 93 | instr = Esplora.readLine().split(',') 94 | return [int(instr[0]), int(instr[1]), int(instr[2]), int(instr[3]), int(instr[4])] 95 | 96 | @staticmethod 97 | def readSlider(): 98 | Esplora._port.write("=S\n") 99 | return int(Esplora.readLine()) 100 | 101 | @staticmethod 102 | def readLightSensor(): 103 | Esplora._port.write("=L\n") 104 | return int(Esplora.readLine()) 105 | 106 | @staticmethod 107 | def readMicrophone(): 108 | Esplora._port.write("=M\n") 109 | return int(Esplora.readLine()) 110 | 111 | @staticmethod 112 | def readTempC(): 113 | Esplora._port.write("=C\n") 114 | return int(Esplora.readLine()) 115 | 116 | @staticmethod 117 | def readTempF(): 118 | Esplora._port.write("=F\n") 119 | return int(Esplora.readLine()) 120 | 121 | @staticmethod 122 | def tftSize(): 123 | Esplora._port.write("=Z\n") 124 | instr = Esplora._port.readline().rstrip().split(",") 125 | return [int(instr[0]), int(instr[1])] 126 | 127 | @staticmethod 128 | def tftBackground(red, green = -1, blue = -1): 129 | if green < 0: 130 | green = red 131 | if blue < 0: 132 | blue = red 133 | Esplora._port.write("SB=%d,%d,%d\n" % (red, green, blue)) 134 | Esplora.sync() 135 | 136 | @staticmethod 137 | def tftFill(red, green = -1, blue = -1): 138 | if green < 0: 139 | green = red 140 | if blue < 0: 141 | blue = red 142 | Esplora._port.write("SF=%d,%d,%d\n" % (red, green, blue)) 143 | Esplora.sync() 144 | 145 | @staticmethod 146 | def tftStroke(red, green = -1, blue = -1): 147 | if green < 0: 148 | green = red 149 | if blue < 0: 150 | blue = red 151 | Esplora._port.write("SS=%d,%d,%d\n" % (red, green, blue)) 152 | Esplora.sync() 153 | 154 | @staticmethod 155 | def tftNoFill(): 156 | Esplora._port.write("SNF\n") 157 | Esplora.sync() 158 | 159 | @staticmethod 160 | def tftNoStroke(): 161 | Esplora._port.write("SNS\n") 162 | Esplora.sync() 163 | 164 | @staticmethod 165 | def tftRect(xpos, ypos, width, height): 166 | Esplora._port.write("SR=%d,%d,%d,%d\n" % (xpos, ypos, width, height)) 167 | Esplora.sync() 168 | 169 | @staticmethod 170 | def tftLine(x1, y1, x2, y2): 171 | Esplora._port.write("SL=%d,%d,%d,%d\n" % (x1, y1, x2, y2)) 172 | Esplora.sync() 173 | 174 | @staticmethod 175 | def tftCircle(xpos, ypos, radius): 176 | Esplora._port.write("SC=%d,%d,%d\n" % (xpos, ypos, radius)) 177 | Esplora.sync() 178 | 179 | @staticmethod 180 | def tftText(string, xpos, ypos): 181 | Esplora._port.write('ST="%s",%d,%d\n' % (string, xpos, ypos)) 182 | Esplora.sync() 183 | 184 | @staticmethod 185 | def tftTextSize(size): 186 | Esplora._port.write('SZ=%d\n' % (size)) 187 | Esplora.sync() 188 | -------------------------------------------------------------------------------- /Processing/Esplora/ex7/ex7.pyde: -------------------------------------------------------------------------------- 1 | """ 2 | Plot Esplora light, sound, and temperature in a scrolling window. 3 | Use Esplora slider to adjust update rate. 4 | """ 5 | add_library('serial') 6 | from Esplora_Processing import Esplora 7 | 8 | # Esplora sensor data lists 9 | light = [0] 10 | sound = [0] 11 | temp = [0] 12 | 13 | def setup(): 14 | global light, sound, temp 15 | Esplora.open(Serial) 16 | size(640, 480) # Nice big window 17 | # Initialize the data lists with middle-of-the-window values 18 | x = 1 19 | while x < width: 20 | light.append(height/2) 21 | sound.append(height/2) 22 | temp.append(height/2) 23 | x = x + 1 24 | 25 | def draw(): 26 | global light, sound, temp 27 | background(0) 28 | # Remove rightmost element from lists 29 | light.pop() 30 | sound.pop() 31 | temp.pop() 32 | # Map full light sensor range 33 | bright = map(Esplora.readLightSensor(), 0, 1023, height - 1, 0) 34 | # Map full sound sensor range 35 | loud = map(Esplora.readMicrophone(), 0, 695, height - 1, 0) 36 | # Map room temperature range 37 | hot = map(Esplora.readTempF(), 40, 100, height - 1, 0) 38 | # Insert new value into beginning of lists 39 | light.insert(0, bright) 40 | sound.insert(0, loud) 41 | temp.insert(0, hot) 42 | # Draw a plot of all three sensors 43 | x = 1 44 | while x < width: 45 | stroke(255, 0, 0) # Red 46 | line(x - 1, temp[x - 1], x, temp[x]) 47 | stroke(0, 255, 0) # Green 48 | line(x - 1, sound[x - 1], x, sound[x]) 49 | stroke(0, 0, 255) # Blue 50 | line(x - 1, light[x - 1], x, light[x]) 51 | x = x + 1 52 | # Use the slider to adjust the update rate between 30 to 1 per second 53 | frameRate(map(Esplora.readSlider(), 0, 1023, 30, 1)) 54 | -------------------------------------------------------------------------------- /Processing/Esplora/ex7/sketch.properties: -------------------------------------------------------------------------------- 1 | mode.id=jycessing.mode.PythonMode 2 | mode=Python 3 | -------------------------------------------------------------------------------- /ProjectorControl/BENQ.gnumeric: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dschmenk/Arduino/035fa38169dec00bfe0aa5b09154b9ad85452e01/ProjectorControl/BENQ.gnumeric -------------------------------------------------------------------------------- /ProjectorControl/ProjectorControl.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Saint Francis Projector Controller 3 | * 4 | #define SERIAL_OUTPUT 5 | */ 6 | #define IR_RECV 5 7 | #define IR_LED 6 8 | #define STATUS_LED 13 9 | #define DOWN_BUTTON 2 10 | #define UP_BUTTON 3 11 | #define SOURCE_BUTTON 4 12 | #define UP_RELAY 7 13 | #define DOWN_RELAY 8 14 | #define LOWER_SECS 15 15 | #define RAISE_SECS 16 16 | 17 | const int irSpace = 500; 18 | const int irOne = 1500; 19 | const int irZero = 500; 20 | const int irHdrHi = 9000; 21 | const int irHdrLo = 4500; 22 | int irBit[] = {irZero, irOne}; 23 | #define IR_SLOP 100 24 | #define IR_TIMEOUT irHdrHi*2 25 | /* 26 | * Benq codes 27 | */ 28 | const word benqPre = 0x000C; 29 | const word benqOn = 0xF20D; 30 | const word benqOff = 0x728D; 31 | const word benqSource = 0x20DF; 32 | const word benqComp = 0x8A75; 33 | const word benqVideo = 0x4AB5; 34 | const word benqSVideo = 0xF807; 35 | const word benqHDMI1 = 0x1AE5; 36 | const word benqHDMI2 = 0x9A65; 37 | const word benqPC = 0x827D; 38 | /* 39 | * Cycle inputs 40 | */ 41 | word benqInputs[] = {benqPC, benqHDMI1}; 42 | byte benqSelIn = 0; 43 | #define MAX_BENQ_INPUTS 2 44 | /* 45 | * Screen position 46 | */ 47 | #define SCREEN_DOWN 1 48 | #define SCREEN_UP 0 49 | byte screenPos = SCREEN_UP; 50 | 51 | void setup() 52 | { 53 | #ifdef SERIAL_OUTPUT 54 | Serial.begin(115200); 55 | Serial.println("St. Francis Smart Projector Switch"); 56 | #endif 57 | digitalWrite(STATUS_LED, LOW); 58 | pinMode(STATUS_LED, OUTPUT); 59 | digitalWrite(IR_LED, LOW); 60 | pinMode(IR_LED, OUTPUT); 61 | pinMode(IR_RECV, INPUT); 62 | pinMode(UP_BUTTON, INPUT_PULLUP); 63 | pinMode(DOWN_BUTTON, INPUT_PULLUP); 64 | pinMode(SOURCE_BUTTON, INPUT_PULLUP); 65 | digitalWrite(UP_RELAY, LOW); 66 | digitalWrite(DOWN_RELAY, LOW); 67 | pinMode(UP_RELAY, OUTPUT); 68 | pinMode(DOWN_RELAY, OUTPUT); 69 | #if 0 70 | int usec = 2; 71 | noInterrupts(); 72 | while (usec > 0) 73 | { 74 | digitalWrite(IR_LED, HIGH); 75 | delayMicroseconds(1); 76 | digitalWrite(IR_LED, LOW); 77 | delayMicroseconds(2); 78 | usec++; 79 | } 80 | #endif 81 | } 82 | 83 | void irWrite(int usec, byte val) 84 | { 85 | /* 86 | * Write 38KHz for useconds 87 | */ 88 | while (usec > 0) 89 | { 90 | digitalWrite(IR_LED, val); 91 | delayMicroseconds(1); 92 | digitalWrite(IR_LED, LOW); 93 | delayMicroseconds(2); 94 | usec -= 26; 95 | } 96 | } 97 | /* 98 | * Send BENQ IR sequence 99 | */ 100 | void benqWriteWord(word val) 101 | { 102 | for (byte i = 0; i < 16; i++) 103 | { 104 | irWrite(irSpace, HIGH); 105 | irWrite(irBit[val & 0x8000 ? 1 : 0], LOW); 106 | val <<= 1; 107 | } 108 | } 109 | void benqSend(word code) 110 | { 111 | /* 112 | * Send header 113 | */ 114 | noInterrupts(); 115 | irWrite(irHdrHi, HIGH); 116 | irWrite(irHdrLo, LOW); 117 | /* 118 | * Send code 119 | */ 120 | benqWriteWord(benqPre); 121 | benqWriteWord(code); 122 | /* 123 | * Send trailer 124 | */ 125 | irWrite(irSpace, HIGH); 126 | interrupts(); 127 | } 128 | word benqRecv(void) 129 | { 130 | word pulse; 131 | unsigned long bitstream; 132 | byte valid = true; 133 | #ifdef SERIAL_OUTPUT 134 | word seq[34]; 135 | byte count = 0; 136 | #endif 137 | if (pulseIn(IR_RECV, LOW, IR_TIMEOUT) > irHdrHi/2) 138 | { 139 | bitstream = 0; 140 | while ((pulse = pulseIn(IR_RECV, HIGH, IR_TIMEOUT))) 141 | { 142 | if (pulse > (irOne-IR_SLOP) && pulse < (irOne+IR_SLOP)) 143 | bitstream = (bitstream << 1) | 1; 144 | else if (pulse > (irZero-IR_SLOP) && pulse < (irZero+IR_SLOP)) 145 | bitstream <<= 1; 146 | else 147 | valid = false; 148 | #ifdef SERIAL_OUTPUT 149 | seq[count++] = pulse; 150 | #endif 151 | } 152 | #ifdef SERIAL_OUTPUT 153 | Serial.print("0x"); Serial.println(bitstream, HEX); 154 | for (byte i = 0; i < count; i++) 155 | Serial.println(seq[i]); 156 | #endif 157 | if (valid && (bitstream>>16) == benqPre) 158 | return (word)bitstream; 159 | } 160 | return 0; 161 | } 162 | void screenLower() 163 | { 164 | #ifdef SERIAL_OUTPUT 165 | Serial.println("Lower Screen..."); 166 | #endif 167 | digitalWrite(DOWN_RELAY, HIGH); 168 | for (byte i = 0; i < 5; i++) 169 | { 170 | benqSend(benqOn); 171 | delay(100); 172 | } 173 | digitalWrite(DOWN_RELAY, LOW); 174 | screenPos = SCREEN_DOWN; 175 | } 176 | 177 | void screenRaise() 178 | { 179 | #ifdef SERIAL_OUTPUT 180 | Serial.println("Raise Screen..."); 181 | #endif 182 | digitalWrite(UP_RELAY, HIGH); 183 | for (byte i = 0; i < 5; i++) 184 | { 185 | benqSend(benqOff); 186 | delay(100); 187 | } 188 | digitalWrite(UP_RELAY, LOW); 189 | screenPos = SCREEN_UP; 190 | } 191 | 192 | void loop() 193 | { 194 | int i; 195 | word benqRepeat; 196 | 197 | /* 198 | * Repeat any IR commands 199 | */ 200 | if ((benqRepeat = benqRecv())) 201 | benqSend(benqRepeat); 202 | /* 203 | * Check button status 204 | */ 205 | if (digitalRead(DOWN_BUTTON) == LOW) // Down button pressed 206 | { 207 | if (screenPos == SCREEN_UP) // If screen up, then lower it 208 | { 209 | screenLower(); 210 | for (i = 0; i < LOWER_SECS; i++) 211 | { 212 | digitalWrite(STATUS_LED, HIGH); 213 | delay(750); 214 | digitalWrite(STATUS_LED, LOW); 215 | delay(250); 216 | } 217 | } 218 | else // Treat down button as source button when screen already down 219 | { 220 | digitalWrite(STATUS_LED, HIGH); 221 | benqSend(benqOn); // Turn it on in case it went to sleep 222 | delay(100); 223 | benqSend(benqOn); 224 | delay(100); 225 | benqSend(benqInputs[benqSelIn]); 226 | delay(100); 227 | benqSend(benqInputs[benqSelIn]); 228 | delay(100); 229 | if (++benqSelIn >= MAX_BENQ_INPUTS) 230 | benqSelIn = 0; 231 | digitalWrite(STATUS_LED, LOW); 232 | while (digitalRead(DOWN_BUTTON) == LOW); // Wait until down button released 233 | } 234 | } 235 | if (digitalRead(UP_BUTTON) == LOW) // Up button pressed 236 | { 237 | screenRaise(); 238 | for (i = 0; i < RAISE_SECS; i++) 239 | { 240 | digitalWrite(STATUS_LED, HIGH); 241 | delay(250); 242 | digitalWrite(STATUS_LED, LOW); 243 | delay(750); 244 | } 245 | } 246 | } 247 | -------------------------------------------------------------------------------- /PyEsplora/Esplora.py: -------------------------------------------------------------------------------- 1 | import serial 2 | import serial.tools.list_ports 3 | import time 4 | 5 | class Esplora: 6 | _port = {} 7 | 8 | @staticmethod 9 | def open(portname = ""): 10 | if portname == "": 11 | ports = serial.tools.list_ports.comports() 12 | portname = ports[len(ports)-1][0] 13 | Esplora._port = serial.Serial(portname, 57600, timeout = 5) 14 | Esplora._port.flushOutput() 15 | Esplora._port.flushInput() 16 | Esplora.sync(5) 17 | 18 | @staticmethod 19 | def close(): 20 | Esplora._port.close() 21 | 22 | @staticmethod 23 | def sync(timeout=1): 24 | Esplora._port.write("!\n") 25 | Esplora._port.readline() 26 | 27 | @staticmethod 28 | def readDigital(pin): 29 | Esplora._port.write("=D%d\n" % pin) 30 | return int(Esplora._port.readline().rstrip()) 31 | 32 | @staticmethod 33 | def readAnalog(pin): 34 | Esplora._port.write("=A%d\n" % pin) 35 | return int(Esplora._port.readline().rstrip()) 36 | 37 | @staticmethod 38 | def writeDigital(pin, value): 39 | if value: 40 | value = 255 41 | Esplora._port.write("D%d=%d\n" % (pin, value)) 42 | 43 | @staticmethod 44 | def writePwm(pin, value): 45 | Esplora._port.write("D%d~%d\n" % (pin, value)) 46 | 47 | @staticmethod 48 | def writeRGB(red, green = -1, blue = -1): 49 | if green < 0: 50 | green = red 51 | if blue < 0: 52 | blue = red 53 | Esplora._port.write("L=%d,%d,%d\n" % (red, green, blue)) 54 | 55 | @staticmethod 56 | def writeBuzzer(hertz = 0, duration = -1): 57 | if duration < 0: 58 | Esplora._port.write("T=%d\n" % hertz) 59 | else: 60 | Esplora._port.write("T=%d,%d\n" % (hertz, duration)) 61 | 62 | @staticmethod 63 | def readJoystick(): 64 | Esplora._port.write("=J\n") 65 | instr = Esplora._port.readline().rstrip().split(",") 66 | Esplora.sync() 67 | return [int(instr[0]), int(instr[1])] 68 | 69 | @staticmethod 70 | def readAccelerometer(): 71 | Esplora._port.write("=X\n") 72 | instr = Esplora._port.readline().rstrip().split(",") 73 | return [int(instr[0]), int(instr[1]), int(instr[2])] 74 | 75 | @staticmethod 76 | def readButtons(): 77 | Esplora._port.write("=B\n") 78 | instr = Esplora._port.readline().rstrip().split(",") 79 | return [int(instr[0]), int(instr[1]), int(instr[2]), int(instr[3]), int(instr[4])] 80 | 81 | @staticmethod 82 | def readSlider(): 83 | Esplora._port.write("=S\n") 84 | return int(Esplora._port.readline().rstrip()) 85 | 86 | @staticmethod 87 | def readLightSensor(): 88 | Esplora._port.write("=L\n") 89 | return int(Esplora._port.readline().rstrip()) 90 | 91 | @staticmethod 92 | def readMicrophone(): 93 | Esplora._port.write("=M\n") 94 | return int(Esplora._port.readline().rstrip()) 95 | 96 | @staticmethod 97 | def readTempC(): 98 | Esplora._port.write("=C\n") 99 | return int(Esplora._port.readline().rstrip()) 100 | 101 | @staticmethod 102 | def readTempF(): 103 | Esplora._port.write("=F\n") 104 | return int(Esplora._port.readline().rstrip()) 105 | 106 | @staticmethod 107 | def tftSize(): 108 | Esplora._port.write("=Z\n") 109 | instr = Esplora._port.readline().rstrip().split(",") 110 | return [int(instr[0]), int(instr[1])] 111 | 112 | @staticmethod 113 | def tftBackground(red, green = -1, blue = -1): 114 | if green < 0: 115 | green = red 116 | if blue < 0: 117 | blue = red 118 | Esplora._port.write("SB=%d,%d,%d\n" % (red, green, blue)) 119 | Esplora.sync() 120 | 121 | @staticmethod 122 | def tftFill(red, green = -1, blue = -1): 123 | if green < 0: 124 | green = red 125 | if blue < 0: 126 | blue = red 127 | Esplora._port.write("SF=%d,%d,%d\n" % (red, green, blue)) 128 | Esplora.sync() 129 | 130 | @staticmethod 131 | def tftStroke(red, green = -1, blue = -1): 132 | if green < 0: 133 | green = red 134 | if blue < 0: 135 | blue = red 136 | Esplora._port.write("SS=%d,%d,%d\n" % (red, green, blue)) 137 | Esplora.sync() 138 | 139 | @staticmethod 140 | def tftNoFill(): 141 | Esplora._port.write("SNF\n") 142 | Esplora.sync() 143 | 144 | @staticmethod 145 | def tftNoStroke(): 146 | Esplora._port.write("SNS\n") 147 | Esplora.sync() 148 | 149 | @staticmethod 150 | def tftRect(xpos, ypos, width, height): 151 | Esplora._port.write("SR=%d,%d,%d,%d\n" % (xpos, ypos, width, height)) 152 | Esplora.sync() 153 | 154 | @staticmethod 155 | def tftLine(x1, y1, x2, y2): 156 | Esplora._port.write("SL=%d,%d,%d,%d\n" % (x1, y1, x2, y2)) 157 | Esplora.sync() 158 | 159 | @staticmethod 160 | def tftCircle(xpos, ypos, radius): 161 | Esplora._port.write("SC=%d,%d,%d\n" % (xpos, ypos, radius)) 162 | Esplora.sync() 163 | 164 | @staticmethod 165 | def tftText(string, xpos, ypos): 166 | Esplora._port.write('ST="%s",%d,%d\n' % (string, xpos, ypos)) 167 | Esplora.sync() 168 | 169 | @staticmethod 170 | def tftTextSize(size): 171 | Esplora._port.write('SZ=%d\n' % (size)) 172 | Esplora.sync() 173 | -------------------------------------------------------------------------------- /PyEsplora/ex.accel.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from Esplora import * 3 | 4 | # 5 | # Open new canvas and connect to Esplora 6 | # 7 | print "Press Switch 1 to exit..." 8 | Esplora.open() 9 | while Esplora.readButtons()[0] != 0: 10 | accel = Esplora.readAccelerometer() 11 | red = (accel[0]) / 2 12 | if red < 0: 13 | red = 0 14 | green = (accel[1]) / 2 15 | if green < 0: 16 | green = 0 17 | blue = (accel[2]) / 2 18 | if blue < 0: 19 | blue = 0 20 | Esplora.writeRGB(red, green, blue) 21 | Esplora.close() 22 | -------------------------------------------------------------------------------- /PyEsplora/ex.joystick.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from Esplora import * 4 | 5 | # 6 | # Open new canvas and connect to Esplora 7 | # 8 | print "Press switch 1 to exit..." 9 | Esplora.open() 10 | while Esplora.readButtons()[0] != 0: 11 | joystick = Esplora.readJoystick() 12 | print joystick 13 | Esplora.close() 14 | -------------------------------------------------------------------------------- /PyEsplora/ex.rgb.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from Esplora import * 4 | 5 | # 6 | # Open new canvas and connect to Esplora 7 | # 8 | print "Press Joystick button to exit..." 9 | Esplora.open() 10 | while Esplora.readButtons()[4] != 0: 11 | joystick = Esplora.readJoystick() 12 | pot = Esplora.readSlider() 13 | red = (joystick[0] + 512) / 4 14 | green = (joystick[1] + 512) / 4 15 | blue = pot / 4 16 | Esplora.writeRGB(red, green, blue) 17 | Esplora.close() 18 | -------------------------------------------------------------------------------- /PyEsplora/ex.tft.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from Esplora import * 4 | 5 | # 6 | # Open new canvas and connect to Esplora 7 | # 8 | Esplora.open() 9 | tftSize = Esplora.tftSize() 10 | Esplora.tftBackground(255,255,255) 11 | Esplora.tftStroke(0,0,0) 12 | for x in xrange(0, tftSize[0], 5): 13 | Esplora.tftLine(0, 0, x, tftSize[1] - 1) 14 | for y in xrange(0, tftSize[1], 5): 15 | Esplora.tftLine(0, 0, tftSize[0] - 1, y) 16 | Esplora.tftFill(128, 0, 255) 17 | Esplora.tftRect(50, 50, 50, 10) 18 | Esplora.tftStroke(0, 255, 128) 19 | Esplora.tftText("Esplora!", 50, 50) 20 | Esplora.close() 21 | -------------------------------------------------------------------------------- /PyEsplora/test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from Tkinter import * 4 | from Esplora import * 5 | 6 | led = 0 7 | 8 | def ledToggle(event): 9 | global led 10 | led = 1 - led 11 | Esplora.writeDigital(13, led) 12 | 13 | def draw(): 14 | angle = (1023 - Esplora.readSlider())/2.84 15 | if angle > 359: 16 | angle = 359 17 | canvas.itemconfig(ovalSpin, extent=angle) 18 | l = Esplora.readLightSensor()/4 19 | color = '#%02x%02x%02x' % (l, l, l) 20 | canvas.itemconfig(ovalLight, fill=color) 21 | l = Esplora.readMicrophone() * 16 22 | if l > 255: 23 | l = 255 24 | color = '#%02x%02x%02x' % (0, l, 0) 25 | canvas.itemconfig(ovalBttn0, fill=color) 26 | l = (Esplora.readTempF() - 65) * 64 27 | if l < 0: 28 | l = 0 29 | if l > 255: 30 | l = 255 31 | color = '#%02x%02x%02x' % (l, 0, 0) 32 | canvas.itemconfig(ovalBttn1, fill=color) 33 | root.after(20, draw) 34 | 35 | # 36 | # Open new canvas and connect to Esplora 37 | # 38 | Esplora.open() 39 | root=Tk() 40 | root.title("Esplora") 41 | canvas=Canvas(root, width = 400, height = 400, bg = 'black') 42 | canvas.bind("", ledToggle) 43 | ovalSpin = canvas.create_arc(10, 10, 190, 190, start=0, extent=1, fill="blue") 44 | ovalLight = canvas.create_oval(210, 10, 390, 190) 45 | ovalBttn0 = canvas.create_oval((10, 210, 190, 390), fill='red') 46 | ovalBttn1 = canvas.create_oval((210, 210, 390, 390), fill='red') 47 | canvas.pack() 48 | root.after(100, draw) 49 | root.mainloop() 50 | Esplora.close() 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Arduino 2 | 3 | ## SPI Video 4 | Use secondary SPI interface as video shift register: https://youtu.be/vEfm9Pm9MkI 5 | 6 | ## Esplora Processing Interface 7 | Arduino, Python, and Processing library source code for tethering the Esplora to a PC running Python/Processing. 8 | 9 | Download the Esplora package for Processing 10 | 1. Open http://github.com/dschmenk/Arduino in Safari. 11 | 2. Click on 'Download ZIP' on right side of screen 12 | 3. Drag the Downloads/Arduino-master folder to the Documents/Processing folder. 13 | 14 | ## Using libraries and modules 15 | Start a new sketch, add the serial port library, import the Esplora module and see how easy it is to use. From the Processing menu, click through "Sketch/Add File..." and add the "Arduino-master/Processing/Esplora/Esplora_Processing.py" file. 16 | 17 | ## A simple example 18 | ``` 19 | add_library('serial') 20 | from Esplora_Processing import Esplora 21 | 22 | def setup(): 23 | Esplora.open(Serial) 24 | 25 | def draw(): 26 | background(map(Esplora.readSlider(), 1023, 0, 0, 255)) 27 | ``` 28 | ## Programming the Esplora firmware 29 | If your Esplora needs to be programmed with the serial protocol firmware for use with Python, open the SerEsplora project in the Arduino IDE and update the Esplora. 30 | 31 | ## Basic API: 32 | Esplora.open(Serial): Open Esplora connection for use 33 | return: None 34 | 35 | Esplora.close(): Close Esplora connection 36 | return: None 37 | 38 | Esplora.writeLED(red, green, blue): Write RGB (or brightness) to LED 39 | return: None 40 | 41 | Esplora.writeBuzzer(hertz, duration): Write buzzer tone 42 | return: None 43 | 44 | Esplora.readJoystick(): Read joystick position 45 | return: [-512..511, -512..511] 46 | 47 | Esplora.readAccelerometer(): Read accelerometer values 48 | return: [-512..511, -512..511, -512..511] 49 | 50 | Esplora.readButtons(): Read 4 diamond pad buttons and joystick button 51 | return: [0..1, 0..1, 0..1, 0..1, 0..1] 52 | 53 | Esplora.readSlider(): Read slider value 54 | return: 0..1023 55 | 56 | Esplora.readLightSensor(): Read light level 57 | return: 0..1023 58 | 59 | Esplora.readMicrophone(): Read sound level 60 | return: 0..1023 61 | 62 | Esplora.readTempC(): Read temperature in Celsius 63 | return: -100..200 64 | 65 | Esplora.readTempF(): Read temperature in Fahrenheit 66 | return: -100..200 67 | 68 | 69 | ## Low-Level API: 70 | Esplora.readDigital(pin): Read the value on a digital pin 71 | return: 0..1 72 | 73 | Esplora.readAnalog(pin): Read the value on an analog pin 74 | return: 0..255 75 | 76 | Esplora.writeDigital(pin, value): Write a value to a digital pin 77 | return: None 78 | 79 | Esplora.writePwm(pin, value): Write a value to an analog (PWM) pin 80 | return: None 81 | 82 | 83 | ## TFT API (for optional Esplora TFT screen): 84 | Esplora.tftSize(): Read the size of the TFT display 85 | return: [tftWidth, tftHeight] 86 | 87 | Esplora.tftBackground(red, green, blue): Fill TFT background with color 88 | return: None 89 | 90 | Esplora.tftFill(red, green, blue): Set fill color for 2D primitives 91 | return: None 92 | 93 | Esplora.tftStroke(red, green, blue): Set stroke color for 2D primitives 94 | return: None 95 | 96 | Esplora.tftNoFill(): Don't fill 2D primitives 97 | return: None 98 | 99 | Esplora.tftNoStroke(): Don't outline 2D primitives 100 | return: None 101 | 102 | Esplora.tftRect(xpos, ypos, width, height): Draw a rectangle 103 | return: None 104 | 105 | Esplora.tftLine(x1, y1, x2, y2): Draw a line 106 | return: None 107 | 108 | Esplora.tftCircle(xpos, ypos, radius): Draw a circle 109 | return: None 110 | 111 | Esplora.tftText(string, xpos, ypos): Draw a text string 112 | return: None 113 | 114 | Esplora.tftTextSize(size): Set the text size 115 | return: None 116 | 117 | 118 | -------------------------------------------------------------------------------- /SIDrive/SIDrive.ino: -------------------------------------------------------------------------------- 1 | // includes 2 | #include 3 | 4 | // SiDrive commands 5 | #define cmdSiS1 0xA0 //SiDrive status Drive 1 6 | #define cmdSiS2 0xA2 //SiDrive status Drive 2 7 | #define cmdSiR1 0xA4 //SiDrive Read Drive 1 8 | #define cmdSiR2 0xA6 //SiDrive Read Drive 2 9 | #define cmdSiW1 0xA8 //SiDrive Write Drive 1 10 | #define cmdSiW2 0xAA //SiDrive Write Drive 2 11 | #define cmdsync 0x80 // Sync packet ack with 0x81 12 | 13 | // system constants 14 | #define GLED 16 // Green LED 15 | #define RLED 15 // Red LED 16 | 17 | // MEGA serial port 2 18 | #define MEGA 19 | #ifdef MEGA 20 | #define SiPort Serial1 21 | #else 22 | #define SiPort Serial 23 | #endif 24 | 25 | // globals 26 | SdFat sd; 27 | SdFile vol1, vol2; 28 | char data[4]; // generic array for holding various things in vsdrive 29 | byte block[513]; // holder for a block of disk data 30 | 31 | void err(char *errstr) 32 | { 33 | #ifdef MEGA 34 | Serial.print(errstr); 35 | Serial.println(" error."); 36 | #else 37 | digitalWrite(GLED, LOW); 38 | digitalWrite(RLED, HIGH); 39 | #endif 40 | sd.errorHalt(); 41 | while (1); 42 | } 43 | 44 | // 45 | // Initialization 46 | // 47 | void setup() 48 | { 49 | #ifndef MEGA 50 | pinMode(GLED, OUTPUT); 51 | pinMode(RLED, OUTPUT); 52 | digitalWrite(GLED, HIGH); 53 | #endif 54 | SiPort.begin(115200); 55 | SiPort.setTimeout(15); 56 | #ifdef MEGA 57 | Serial.begin(9600); 58 | if (!sd.begin(4, SPI_FULL_SPEED)) err("Can't enable SDcard"); //pin 4 when using ethernet shield 59 | #else 60 | if (!sd.begin(SS, SPI_FULL_SPEED)) err("Can't enable SDcard"); // SS on VDriveSSC 61 | #endif 62 | if (!vol1.open("Virtual.po", O_RDWR | O_SYNC)) err("Can't open Virtial.po"); 63 | if (!vol2.open("Virtual2.po", O_RDWR | O_SYNC)) err("Can't open Virtual2.po"); 64 | } 65 | 66 | // Global Functions 67 | void access(byte acc) // LED blinking 68 | { 69 | #ifndef MEGA 70 | if(acc) 71 | { 72 | digitalWrite(GLED, LOW); 73 | digitalWrite(RLED, HIGH); 74 | } 75 | else 76 | { 77 | digitalWrite(RLED, LOW); 78 | digitalWrite(GLED, HIGH); 79 | } 80 | #endif 81 | } 82 | 83 | int ReadSerial() 84 | { 85 | if (SiPort.available()) 86 | return byte(SiPort.read()); 87 | return -1; 88 | } 89 | 90 | // SiDrive commands 91 | void SiStat(SdFile *vol) 92 | { 93 | unsigned int blockSize; 94 | 95 | SiPort.readBytes(data,2); // Read 2 bytes, dummy data 96 | blockSize = vol->fileSize() >> 9; // div by 512 97 | data[0] = blockSize; 98 | data[1] = blockSize >> 8; 99 | SiPort.write(data, 2); // send volume file size 100 | SiPort.write(blockSize ? 0x00 : 0xA8); 101 | } 102 | 103 | void SiRead(SdFile *vol) 104 | { 105 | SiPort.readBytes(data,2); // Read 2 byte block num 106 | access(1); 107 | // set file pointer 108 | vol->seekSet((word(data[1], data[0]) * 512UL)); 109 | vol->read(block,512); // read block data 110 | SiPort.write(block,512); // send block data 111 | access(0); 112 | SiPort.write(0x00); // send checksum 113 | } 114 | 115 | void SiWrite(SdFile *vol) 116 | { 117 | SiPort.readBytes(data,2); // Read 2 byte block num 118 | SiPort.readBytes((char*)block, 512); // read block data and checksum 119 | access(1); 120 | // write data to SD card 121 | vol->seekSet((word(data[1], data[0]) * 512UL)); 122 | vol->write(block,512); 123 | access(0); 124 | SiPort.write(0x00); // return 0x00 125 | } 126 | 127 | // 128 | // Main command handler 129 | // 130 | void loop() 131 | { 132 | int cmd; 133 | 134 | if ((cmd = ReadSerial()) >= 0) 135 | { 136 | #ifdef MEGA 137 | Serial.println(cmd, HEX); 138 | #endif 139 | if (cmd) SiPort.write(cmd+1); // Acknowledge command 140 | switch(cmd) 141 | { 142 | case cmdSiR1: 143 | SiRead(&vol1); 144 | break; 145 | case cmdSiR2: 146 | SiRead(&vol2); 147 | break; 148 | case cmdSiW1: 149 | SiWrite(&vol1); 150 | break; 151 | case cmdSiW2: 152 | SiWrite(&vol2); 153 | break; 154 | case cmdSiS1: 155 | SiStat(&vol1); 156 | break; 157 | case cmdSiS2: 158 | SiStat(&vol2); 159 | break; 160 | case cmdsync: 161 | vol1.sync(); 162 | vol2.sync(); 163 | break; 164 | } 165 | SiPort.flush(); 166 | } 167 | } 168 | 169 | -------------------------------------------------------------------------------- /SerEsplora/SerEsplora.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /* 6 | One time initialization. 7 | */ 8 | void setup() 9 | { 10 | // initialize serial: 11 | Serial.begin(57600); 12 | while (!Serial) { 13 | ; // wait for serial port to connect. Needed for Leonardo only 14 | } 15 | // initialize TFT screen 16 | EsploraTFT.begin(); 17 | } 18 | 19 | void parseRGB(byte *red, byte *green, byte *blue) 20 | { 21 | if (Serial.read() != '=') 22 | return; 23 | *red = Serial.parseInt(); 24 | if (Serial.read() != ',') 25 | { 26 | *green = *red; 27 | *blue = *red; 28 | } 29 | else 30 | { 31 | *green = Serial.parseInt(); 32 | if (Serial.read() == ',') 33 | *blue = Serial.parseInt(); 34 | else 35 | *blue = 0; 36 | } 37 | } 38 | 39 | void loop() 40 | { 41 | int pin, val, x1, y1, x2, y2; 42 | byte red, green, blue; 43 | char string[40]; 44 | 45 | if (Serial.available()) 46 | { 47 | switch (Serial.read()) 48 | { 49 | case '!': // Synchronize 50 | Serial.println("!"); 51 | break; 52 | case '=': // Read a value 53 | switch (Serial.read()) 54 | { 55 | case 'D': // Read digital pin 56 | case 'd': 57 | pin = Serial.parseInt(); 58 | pinMode(pin, INPUT); 59 | Serial.println(digitalRead(pin)); 60 | break; 61 | case 'A': // Read analog pin 62 | case 'a': 63 | pin = Serial.parseInt() + A0; 64 | pinMode(pin, INPUT); 65 | Serial.println(analogRead(pin)); 66 | break; 67 | case 'X': // Read accelerometer 68 | case 'x': 69 | Serial.print(Esplora.readAccelerometer(X_AXIS));Serial.print(","); 70 | Serial.print(Esplora.readAccelerometer(Y_AXIS));Serial.print(","); 71 | Serial.println(Esplora.readAccelerometer(Z_AXIS)); 72 | break; 73 | case 'J': // Read joystick 74 | case 'j': 75 | Serial.print(Esplora.readJoystickX());Serial.print(","); 76 | Serial.println(Esplora.readJoystickY()); 77 | break; 78 | case 'B': // Read button pad 79 | case 'b': 80 | Serial.print(Esplora.readButton(1));Serial.print(","); 81 | Serial.print(Esplora.readButton(2));Serial.print(","); 82 | Serial.print(Esplora.readButton(3));Serial.print(","); 83 | Serial.print(Esplora.readButton(4));Serial.print(","); 84 | Serial.println(Esplora.readJoystickSwitch()); 85 | break; 86 | case 'S': // Read slider 87 | case 's': 88 | Serial.println(Esplora.readSlider()); 89 | break; 90 | case 'L': // Read light sensor 91 | case 'l': 92 | Serial.println(Esplora.readLightSensor()); 93 | break; 94 | case 'M': // Read microphone 95 | case 'm': 96 | Serial.println(Esplora.readMicrophone()); 97 | break; 98 | case 'C': // Read temperature in Celcius 99 | case 'c': 100 | Serial.println(Esplora.readTemperature(DEGREES_C)); 101 | break; 102 | case 'F': // Read temperature in Celcius 103 | case 'f': 104 | Serial.println(Esplora.readTemperature(DEGREES_F)); 105 | break; 106 | case 'Z': // Read TFT screen size 107 | case 'z': 108 | Serial.print(EsploraTFT.width());Serial.print(","); 109 | Serial.println(EsploraTFT.height()); 110 | break; 111 | } 112 | break; 113 | case 'D': // Write digital pin 114 | case 'd': 115 | pin = Serial.parseInt(); 116 | switch (Serial.read()) 117 | { 118 | case '=': // Binary 119 | val = Serial.parseInt() ? HIGH : LOW; 120 | pinMode(pin, OUTPUT); 121 | digitalWrite(pin, val); 122 | break; 123 | case '~': // PWM 124 | val = Serial.parseInt(); 125 | pinMode(pin, OUTPUT); 126 | analogWrite(pin, val); 127 | break; 128 | } 129 | break; 130 | case 'A': // Write analog pin 131 | case 'a': 132 | pin = Serial.parseInt() + A0; 133 | if (Serial.read() != '=') 134 | break; 135 | val = Serial.parseInt(); 136 | pinMode(pin, OUTPUT); 137 | digitalWrite(pin, val); 138 | break; 139 | case 'L': // Write RGB LED 140 | case 'l': 141 | parseRGB(&red, &green, &blue); 142 | Esplora.writeRGB(red, green, blue); 143 | break; 144 | case 'T': // Write tone 145 | case 't': 146 | if (Serial.read() != '=') 147 | break; 148 | val = Serial.parseInt(); 149 | if (Serial.read() == ',') 150 | Esplora.tone(val, Serial.parseInt()); 151 | else 152 | Esplora.tone(val); 153 | break; 154 | case 'S': // call TFT screen functions 155 | case 's': 156 | switch (Serial.read()) 157 | { 158 | case 'B': // background 159 | case 'b': 160 | parseRGB(&red, &green, &blue); 161 | EsploraTFT.background(blue, green, red); 162 | break; 163 | case 'F': // fill color 164 | case 'f': 165 | parseRGB(&red, &green, &blue); 166 | EsploraTFT.fill(blue, green, red); 167 | break; 168 | case 'S': // stroke color 169 | case 's': 170 | parseRGB(&red, &green, &blue); 171 | EsploraTFT.stroke(blue, green, red); 172 | break; 173 | case 'N': // no stroke/fill 174 | case 'n': 175 | switch (Serial.read()) 176 | { 177 | case 'S': // no stroke 178 | case 's': 179 | EsploraTFT.noStroke(); 180 | break; 181 | case 'F': // no fill 182 | case 'f': 183 | EsploraTFT.noFill(); 184 | break; 185 | } 186 | break; 187 | case 'R': // rect 188 | case 'r': 189 | if (Serial.read() != '=') 190 | break; 191 | x1 = Serial.parseInt(); 192 | if (Serial.read() != ',') 193 | break; 194 | y1 = Serial.parseInt(); 195 | if (Serial.read() != ',') 196 | break; 197 | x2 = Serial.parseInt(); 198 | if (Serial.read() != ',') 199 | break; 200 | y2 = Serial.parseInt(); 201 | EsploraTFT.rect(x1, y1, x2, y2); 202 | break; 203 | case 'L': // line 204 | case 'l': 205 | if (Serial.read() != '=') 206 | break; 207 | x1 = Serial.parseInt(); 208 | if (Serial.read() != ',') 209 | break; 210 | y1 = Serial.parseInt(); 211 | if (Serial.read() != ',') 212 | break; 213 | x2 = Serial.parseInt(); 214 | if (Serial.read() != ',') 215 | break; 216 | y2 = Serial.parseInt(); 217 | EsploraTFT.line(x1, y1, x2, y2); 218 | break; 219 | case 'C': // circle 220 | case 'c': 221 | if (Serial.read() != '=') 222 | break; 223 | x1 = Serial.parseInt(); 224 | if (Serial.read() != ',') 225 | break; 226 | y1 = Serial.parseInt(); 227 | if (Serial.read() != ',') 228 | break; 229 | x2 = Serial.parseInt(); 230 | EsploraTFT.circle(x1, y1, x2); 231 | break; 232 | case 'P': // point 233 | case 'p': 234 | if (Serial.read() != '=') 235 | break; 236 | x1 = Serial.parseInt(); 237 | if (Serial.read() != ',') 238 | break; 239 | y1 = Serial.parseInt(); 240 | if (Serial.read() != ',') 241 | break; 242 | EsploraTFT.point(x1, y1); 243 | break; 244 | case 'T': // text 245 | case 't': 246 | if (Serial.read() != '=') 247 | break; 248 | if (Serial.read() != '\"') 249 | break; 250 | val = 0; 251 | while ((pin = Serial.read()) != '\"') 252 | { 253 | string[val++] = pin; 254 | } 255 | string[val++] = '\0'; 256 | if (Serial.read() != ',') 257 | break; 258 | x1 = Serial.parseInt(); 259 | if (Serial.read() != ',') 260 | break; 261 | y1 = Serial.parseInt(); 262 | EsploraTFT.text(string, x1, y1); 263 | break; 264 | case 'Z': // text size 265 | case 'z': 266 | if (Serial.read() != '=') 267 | break; 268 | val = Serial.parseInt(); 269 | EsploraTFT.setTextSize(val); 270 | break; 271 | default: 272 | Serial.println('?'); 273 | } 274 | break; 275 | case '\n': 276 | break; 277 | default: 278 | Serial.println('?'); 279 | } 280 | } 281 | } 282 | 283 | -------------------------------------------------------------------------------- /VideoSPI/VideoSPI.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Output NTSC video using the UART in SPI master mode on Arduino Uno. 3 | * 40x25 character buffer is rasterized and scanned out in real-time. 4 | * 320X200 pixels out of 1000 RAM bytes and 1K Flash character ROM. 5 | * VIDEO on pin 1 (470 ohm resistor), SYNC on pin 9 (1K ohm resistor). 6 | * 7 | * Blatantly using code from: 8 | * TVout - http://playground.arduino.cc/Main/TVout 9 | * VGAout - http://www.gammon.com.au/forum/?id=11608 10 | * Color TVout using SPI - http://www.hackster.io/janost/avr-videoblaster 11 | * 12 | * Dave Schmenk 13 | */ 14 | // 15 | // Timing settings for NTSC 16 | // 17 | #define _CYCLES_PER_US (F_CPU / 1000000) 18 | #define _TIME_HSYNC 4.7 19 | #define _TIME_VSYNC 58.85 20 | #define _TIME_ACTIVE 46 21 | #define _CYCLES_VSYNC ((_TIME_VSYNC * _CYCLES_PER_US) - 1) 22 | #define _CYCLES_HSYNC ((_TIME_HSYNC * _CYCLES_PER_US) - 1) 23 | #define _NTSC_TIME_SCANLINE 63.55 24 | #define _NTSC_TIME_OUTPUT_START 12 25 | #define _NTSC_LINE_FRAME 262 26 | #define _NTSC_LINE_START_VSYNC 0 27 | #define _NTSC_LINE_STOP_VSYNC 3 28 | #define _NTSC_LINE_DISPLAY 216 29 | #define _NTSC_LINE_MID ((_NTSC_LINE_FRAME - _NTSC_LINE_DISPLAY)/2 + _NTSC_LINE_DISPLAY/2 + _NTSC_LINE_STOP_VSYNC) 30 | #define _NTSC_CYCLES_SCANLINE ((_NTSC_TIME_SCANLINE * _CYCLES_PER_US) - 1) 31 | #define _NTSC_CYCLES_OUTPUT_START ((_NTSC_TIME_OUTPUT_START * _CYCLES_PER_US) - 1) 32 | // 33 | // video = UART SPI TX 34 | // 35 | #define PORT_VID PORTD 36 | #define DDR_VID DDRD 37 | #define VID_PIN 1 38 | #define XCK0_DDR DDRD 39 | #define XCK0 4 40 | // 41 | // sync = OC1A 42 | // 43 | #define PORT_SYNC PORTB 44 | #define DDR_SYNC DDRB 45 | #define SYNC_PIN 1 46 | // 47 | // video buffer 48 | // 49 | #define VID_WIDTH 40 50 | #define VID_HEIGHT 25 51 | #define CELL_WIDTH 8 52 | #define CELL_HEIGHT 8 53 | byte xpos=0; 54 | byte ypos=0; 55 | char videomem[VID_WIDTH*VID_HEIGHT]; 56 | // 57 | // rendering values 58 | // 59 | char *videoptr = videomem; 60 | int scanline=0; 61 | void (*line_handler)(void) = &blank_line; 62 | volatile byte vblank=0; 63 | // 64 | // character definitions 65 | // 66 | PROGMEM const byte charROM [1024] = { 67 | 0x00,0xF0,0x0F,0xFF,0x00,0xF0,0x0F,0xFF,0x00,0xF0,0x0F,0xFF,0x00,0xF0,0x0F,0xFF,0x80,0x01,0xFF,0x18,0x18,0x18,0x00,0x18,0xFF,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x30,0x6C,0x6C,0x30,0x00,0x38,0x60,0x18,0x60,0x00,0x00,0x00,0x00,0x00,0x06,0x7C,0x30,0x78,0x78,0x1C,0xFC,0x38,0xFC,0x78,0x78,0x00,0x00,0x18,0x00,0x60,0x78,0x7C,0x30,0xFC,0x3C,0xF8,0xFE,0xFE,0x3C,0xCC,0x78,0x1E,0xE6,0xF0,0xC6,0xC6,0x38,0xFC,0x78,0xFC,0x78,0xFC,0xCC,0xCC,0xC6,0xC6,0xCC,0xFE,0x78,0xC0,0x78,0x10,0x00,0x30,0x00,0xE0,0x00,0x1C,0x00,0x38,0x00,0xE0,0x30,0x0C,0xE0,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x18,0xE0,0x76,0xAA, 68 | 0x00,0xF0,0x0F,0xFF,0x00,0xF0,0x0F,0xFF,0x00,0xF0,0x0F,0xFF,0x00,0xF0,0x0F,0xFF,0xE0,0x07,0xFF,0x18,0x18,0x18,0x00,0x18,0xFF,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x78,0x6C,0x6C,0x7C,0xC6,0x6C,0x60,0x30,0x30,0x66,0x30,0x00,0x00,0x00,0x0C,0xC6,0x70,0xCC,0xCC,0x3C,0xC0,0x60,0xCC,0xCC,0xCC,0x30,0x30,0x30,0x00,0x30,0xCC,0xC6,0x78,0x66,0x66,0x6C,0x62,0x62,0x66,0xCC,0x30,0x0C,0x66,0x60,0xEE,0xE6,0x6C,0x66,0xCC,0x66,0xCC,0xB4,0xCC,0xCC,0xC6,0xC6,0xCC,0xC6,0x60,0x60,0x18,0x38,0x00,0x30,0x00,0x60,0x00,0x0C,0x00,0x6C,0x00,0x60,0x00,0x00,0x60,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x18,0x30,0xDC,0x55, 69 | 0x00,0xF0,0x0F,0xFF,0x00,0xF0,0x0F,0xFF,0x00,0xF0,0x0F,0xFF,0x00,0xF0,0x0F,0xFF,0xF8,0x1F,0xC3,0x18,0x3C,0x18,0x00,0x18,0x7E,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x78,0x6C,0xFE,0xC0,0xCC,0x38,0xC0,0x60,0x18,0x3C,0x30,0x00,0x00,0x00,0x18,0xCE,0x30,0x0C,0x0C,0x6C,0xF8,0xC0,0x0C,0xCC,0xCC,0x30,0x30,0x60,0xFC,0x18,0x0C,0xDE,0xCC,0x66,0xC0,0x66,0x68,0x68,0xC0,0xCC,0x30,0x0C,0x6C,0x60,0xFE,0xF6,0xC6,0x66,0xCC,0x66,0xE0,0x30,0xCC,0xCC,0xC6,0x6C,0xCC,0x8C,0x60,0x30,0x18,0x6C,0x00,0x18,0x78,0x60,0x78,0x0C,0x78,0x60,0x76,0x6C,0x70,0x0C,0x66,0x30,0xCC,0xF8,0x78,0xDC,0x76,0xDC,0x7C,0x7C,0xCC,0xCC,0xC6,0xC6,0xCC,0xFC,0x30,0x18,0x30,0x00,0xAA, 70 | 0x00,0xF0,0x0F,0xFF,0x00,0xF0,0x0F,0xFF,0x00,0xF0,0x0F,0xFF,0x00,0xF0,0x0F,0xFF,0xFE,0x7F,0xC3,0x1F,0x3C,0x18,0x1F,0x1F,0x7E,0xF8,0xFF,0xFF,0xF8,0xF8,0xFF,0xFF,0x00,0x30,0x00,0x6C,0x78,0x18,0x76,0x00,0x60,0x18,0xFF,0xFC,0x00,0xFC,0x00,0x30,0xDE,0x30,0x38,0x38,0xCC,0x0C,0xF8,0x18,0x78,0x7C,0x00,0x00,0xC0,0x00,0x0C,0x18,0xDE,0xCC,0x7C,0xC0,0x66,0x78,0x78,0xC0,0xFC,0x30,0x0C,0x78,0x60,0xFE,0xDE,0xC6,0x7C,0xCC,0x7C,0x70,0x30,0xCC,0xCC,0xD6,0x38,0x78,0x18,0x60,0x18,0x18,0xC6,0x00,0x00,0x0C,0x7C,0xCC,0x7C,0xCC,0xF0,0xCC,0x76,0x30,0x0C,0x6C,0x30,0xFE,0xCC,0xCC,0x66,0xCC,0x76,0xC0,0x30,0xCC,0xCC,0xD6,0x6C,0xCC,0x98,0xE0,0x00,0x1C,0x00,0x55, 71 | 0x00,0x00,0x00,0x00,0xF0,0xF0,0xF0,0xF0,0x0F,0x0F,0x0F,0x0F,0xFF,0xFF,0xFF,0xFF,0xFE,0x7F,0xC3,0x1F,0x7E,0x18,0x1F,0x1F,0x3C,0xF8,0xFF,0xFF,0xF8,0xF8,0xFF,0xFF,0x00,0x30,0x00,0xFE,0x0C,0x30,0xDC,0x00,0x60,0x18,0x3C,0x30,0x00,0x00,0x00,0x60,0xF6,0x30,0x60,0x0C,0xFE,0x0C,0xCC,0x30,0xCC,0x0C,0x00,0x00,0x60,0x00,0x18,0x30,0xDE,0xFC,0x66,0xC0,0x66,0x68,0x68,0xCE,0xCC,0x30,0xCC,0x6C,0x62,0xD6,0xCE,0xC6,0x60,0xDC,0x6C,0x1C,0x30,0xCC,0xCC,0xFE,0x38,0x30,0x32,0x60,0x0C,0x18,0x00,0x00,0x00,0x7C,0x66,0xC0,0xCC,0xFC,0x60,0xCC,0x66,0x30,0x0C,0x78,0x30,0xFE,0xCC,0xCC,0x66,0xCC,0x66,0x78,0x30,0xCC,0xCC,0xFE,0x38,0xCC,0x30,0x30,0x18,0x30,0x00,0xAA, 72 | 0x00,0x00,0x00,0x00,0xF0,0xF0,0xF0,0xF0,0x0F,0x0F,0x0F,0x0F,0xFF,0xFF,0xFF,0xFF,0xF8,0x1F,0xC3,0x00,0x7E,0x18,0x18,0x18,0x3C,0x00,0x00,0x00,0x18,0x18,0x18,0x18,0x00,0x00,0x00,0x6C,0xF8,0x66,0xCC,0x00,0x30,0x30,0x66,0x30,0x30,0x00,0x30,0xC0,0xE6,0x30,0xCC,0xCC,0x0C,0xCC,0xCC,0x30,0xCC,0x18,0x30,0x30,0x30,0xFC,0x30,0x00,0xC0,0xCC,0x66,0x66,0x6C,0x62,0x60,0x66,0xCC,0x30,0xCC,0x66,0x66,0xC6,0xC6,0x6C,0x60,0x78,0x66,0xCC,0x30,0xCC,0x78,0xEE,0x6C,0x30,0x66,0x60,0x06,0x18,0x00,0x00,0x00,0xCC,0x66,0xCC,0xCC,0xC0,0x60,0x7C,0x66,0x30,0xCC,0x6C,0x30,0xD6,0xCC,0xCC,0x7C,0x7C,0x60,0x0C,0x34,0xCC,0x78,0xFE,0x6C,0x7C,0x64,0x30,0x18,0x30,0x00,0x55, 73 | 0x00,0x00,0x00,0x00,0xF0,0xF0,0xF0,0xF0,0x0F,0x0F,0x0F,0x0F,0xFF,0xFF,0xFF,0xFF,0xE0,0x07,0xFF,0x00,0xFF,0x18,0x18,0x18,0x18,0x00,0x00,0x00,0x18,0x18,0x18,0x18,0x00,0x30,0x00,0x6C,0x30,0xC6,0x76,0x00,0x18,0x60,0x00,0x00,0x30,0x00,0x30,0x80,0x7C,0xFC,0xFC,0x78,0x1E,0x78,0x78,0x30,0x78,0x70,0x30,0x30,0x18,0x00,0x60,0x30,0x78,0xCC,0xFC,0x3C,0xF8,0xFE,0xF0,0x3E,0xCC,0x78,0x78,0xE6,0xFE,0xC6,0xC6,0x38,0xF0,0x1C,0xE6,0x78,0x78,0xFC,0x30,0xC6,0xC6,0x78,0xFE,0x78,0x02,0x78,0x00,0x00,0x00,0x76,0xDC,0x78,0x76,0x78,0xF0,0x0C,0xE6,0x78,0xCC,0xE6,0x78,0xC6,0xCC,0x78,0x60,0x0C,0xF0,0xF8,0x18,0x76,0x30,0x6C,0xC6,0x0C,0xFC,0x1C,0x18,0xE0,0x00,0xAA, 74 | 0x00,0x00,0x00,0x00,0xF0,0xF0,0xF0,0xF0,0x0F,0x0F,0x0F,0x0F,0xFF,0xFF,0xFF,0xFF,0x80,0x01,0xFF,0x00,0xFF,0x18,0x18,0x18,0x18,0x00,0x00,0x00,0x18,0x18,0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x00,0x00,0x78,0x00,0x00,0x00,0x00,0x00,0xF0,0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x55, 75 | }; 76 | /* 77 | * Set up UART SPI master mode and timers for sync pulses 78 | */ 79 | void setup(void) 80 | { 81 | cli(); 82 | UBRR0 = 0; // must be zero before enabling the transmitter 83 | XCK0_DDR |= _BV(XCK0); // set XCK pin as output to enable master mode 84 | UCSR0C = _BV (UMSEL00) | _BV (UMSEL01); // SPI master mode 85 | DDR_VID |= _BV(VID_PIN); 86 | DDR_SYNC |= _BV(SYNC_PIN); 87 | PORT_VID &= ~_BV(VID_PIN); 88 | PORT_SYNC |= _BV(SYNC_PIN); 89 | TCCR1A = _BV(COM1A1) | _BV(COM1A0) | _BV(WGM11); // inverted fast pwm mode on timer 2 90 | TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); 91 | ICR1 = _NTSC_CYCLES_SCANLINE; 92 | OCR1A = _CYCLES_HSYNC; 93 | OCR1B = _NTSC_CYCLES_OUTPUT_START - 79; 94 | TIMSK1 = _BV(OCIE1B); 95 | TIMSK0 = 0; // turn timer0 off! 96 | SMCR = _BV(SE); // allow IDLE sleep mode 97 | sei(); 98 | // 99 | // Clear the video buffer and print out sample text 100 | // 101 | chrout(12); 102 | printstr("0123456789012345678901234567890123456789"); 103 | printstr("\n Video SPI Demo\n\n"); 104 | for (byte i = ' '; i < 128; i++) 105 | chrout(i); 106 | box(0, 9, 19, 15); 107 | clrrect(20,9, 19, 15, 0); 108 | box(20,9,19,15); 109 | } 110 | // 111 | // Handle scanline timing 112 | // 113 | ISR(TIMER1_COMPA_vect) 114 | { 115 | sei(); 116 | asm("sleep\n"); // for clock synchronization during active lines 117 | } 118 | ISR(TIMER1_COMPB_vect) 119 | { 120 | line_handler(); 121 | scanline++; 122 | } 123 | // 124 | // Inactive scanlines 125 | // 126 | void blank_line(void) 127 | { 128 | if (scanline == _NTSC_LINE_STOP_VSYNC) 129 | { 130 | OCR1A = _CYCLES_HSYNC; 131 | } 132 | else if ( scanline == _NTSC_LINE_MID - (VID_HEIGHT*CELL_HEIGHT)/2) 133 | { 134 | TIMSK1 = _BV(OCIE1A) | _BV(OCIE1B); 135 | videoptr = videomem; 136 | line_handler = &active_line; 137 | } 138 | else if (scanline > _NTSC_LINE_FRAME) 139 | { 140 | OCR1A = _CYCLES_VSYNC; 141 | scanline = 0; 142 | } 143 | } 144 | // 145 | // Active scanlines 146 | // 147 | void active_line(void) 148 | { 149 | register char *charPtr; 150 | register int charCol; 151 | byte p ; 152 | static byte charRow = 0; 153 | 154 | UDR0 = 0; 155 | UCSR0B = _BV(TXEN0); // this spits out an idle bit (white pixel) so move it off the left side of the screen 156 | charPtr = videoptr; 157 | while ((UCSR0A & _BV (UDRE0)) == 0); 158 | UDR0 = 0; 159 | charCol = (int)&charROM + (charRow<<7); // overlap with some initialization 160 | while ((UCSR0A & _BV (UDRE0)) == 0); 161 | UDR0 = 0; 162 | while ((UCSR0A & _BV (UDRE0)) == 0); 163 | UDR0 = 0; 164 | while ((UCSR0A & _BV (UDRE0)) == 0); 165 | UDR0 = 0; 166 | p = VID_WIDTH; 167 | while ((UCSR0A & _BV (UDRE0)) == 0); 168 | UDR0 = 0; 169 | while (p--) // draw the character line 170 | UDR0 = pgm_read_byte_near(charCol + *charPtr++); 171 | while ((UCSR0A & _BV (TXC0)) == 0); // wait for pixels to shift out 172 | UCSR0B = 0; 173 | if (++charRow == CELL_HEIGHT) 174 | { 175 | charRow = 0; 176 | if (scanline == _NTSC_LINE_MID + (VID_HEIGHT*CELL_HEIGHT)/2) 177 | { 178 | TIMSK1 = _BV(OCIE1B); 179 | line_handler = &blank_line; 180 | vblank=1; // signal new frame 181 | } 182 | else 183 | { 184 | videoptr += VID_WIDTH; 185 | } 186 | } 187 | } 188 | /* 189 | * Character output routines. 190 | */ 191 | void chrout(char ascii) 192 | { 193 | switch (ascii) { 194 | case 10: 195 | xpos=0; 196 | ypos++; 197 | if (ypos>=VID_HEIGHT) { 198 | scrollscr(); 199 | xpos=0; 200 | ypos=VID_HEIGHT-1; 201 | } 202 | break; 203 | case 12: 204 | clrscr(' '); 205 | xpos=0; 206 | ypos=0; 207 | break; 208 | default: 209 | if (ascii >= ' ' && ascii < 128) { 210 | videomem[xpos+ypos*VID_WIDTH] = ascii; 211 | xpos++; 212 | if (xpos>=VID_WIDTH) { 213 | xpos=0; 214 | ypos++; 215 | if (ypos>=VID_HEIGHT) { 216 | scrollscr(); 217 | xpos=0; 218 | ypos=VID_HEIGHT-1; 219 | } 220 | } 221 | } 222 | } 223 | } 224 | void clrscr(byte val) 225 | { 226 | for (int i = VID_WIDTH*VID_HEIGHT-1; i >= 0; --i) 227 | videomem[i] = val; 228 | } 229 | void clrrect(byte x, byte y, byte w, byte h, byte v) 230 | { 231 | byte i, j; 232 | char *vptr = &videomem[x + y * VID_WIDTH]; 233 | for (j = 0; j < h; j++) 234 | { 235 | for (i = 0; i < w; i++) 236 | *vptr++ = v; 237 | vptr += VID_WIDTH - w; 238 | } 239 | } 240 | void box(byte x, byte y, byte w, byte h) 241 | { 242 | byte i, j; 243 | char *vptr = &videomem[x + y * VID_WIDTH]; 244 | *vptr++ = 0x16; 245 | for (i = 1; i < w; i++) 246 | *vptr++ = 0x1A; 247 | *vptr = 0x1C; 248 | vptr += VID_WIDTH - w; 249 | for (j = 1; j < h; j++) 250 | { 251 | vptr[0] = 0x15; 252 | vptr[w] = 0x15; 253 | vptr += VID_WIDTH; 254 | } 255 | *vptr++ = 0x13; 256 | for (i = 1; i < w; i++) 257 | *vptr++ = 0x1A; 258 | *vptr = 0x19; 259 | } 260 | void scrollscr(void) 261 | { 262 | for (unsigned int i=VID_WIDTH; i < VID_WIDTH*VID_HEIGHT; i++) 263 | videomem[i-VID_WIDTH]=videomem[i]; 264 | for (unsigned int i=VID_WIDTH*VID_HEIGHT - VID_WIDTH; i < VID_WIDTH*VID_HEIGHT; i++) 265 | videomem[i]=' '; 266 | } 267 | void printstr(char *string) 268 | { 269 | while(*string) 270 | chrout(*string++); 271 | } 272 | void gotoxy(int x, int y) 273 | { 274 | if (x < 0) x = 0; 275 | if (x > VID_WIDTH-1) x = VID_WIDTH-1; 276 | if (y < 0) y = 0; 277 | if (y > VID_HEIGHT-1) y = VID_HEIGHT-1; 278 | xpos = x; 279 | ypos = y; 280 | } 281 | // 282 | // Plot lores pixels 283 | // 284 | void setpix(signed char x, signed char y) 285 | { 286 | byte xChar, yChar, blockChar; 287 | 288 | if (x > 79 || x < 0 || y > 49 || y < 0) 289 | return; 290 | xChar = x >> 1; 291 | yChar = y >> 1; 292 | blockChar = 1 << ((x & 1) | ((y & 1) << 1)); 293 | videomem[xChar + yChar * VID_WIDTH] |= blockChar; 294 | } 295 | void clrpix(signed char x, signed char y) 296 | { 297 | byte xChar, yChar, blockChar; 298 | 299 | if (x > 79 || x < 0 || y > 49 || y < 0) 300 | return; 301 | xChar = x >> 1; 302 | yChar = y >> 1; 303 | blockChar = 1 << ((x & 1) | ((y & 1) << 1)); 304 | videomem[xChar + yChar * VID_WIDTH] &= ~blockChar; 305 | } 306 | void xorpix(signed char x, signed char y) 307 | { 308 | byte xChar, yChar, blockChar; 309 | 310 | if (x > 79 || x < 0 || y > 49 || y < 0) 311 | return; 312 | xChar = x >> 1; 313 | yChar = y >> 1; 314 | blockChar = 1 << ((x & 1) | ((y & 1) << 1)); 315 | videomem[xChar + yChar * VID_WIDTH] ^= blockChar; 316 | } 317 | void line(signed char x1, signed char y1, signed char x2, signed char y2, void (*oppix)(signed char x, signed char y)) 318 | { 319 | signed char dx, dy, sx, sy, dx2, dy2, dd2, err; 320 | 321 | if (x2 >= x1) 322 | { 323 | dx = x2 - x1; 324 | sx = 1; 325 | } 326 | else 327 | { 328 | dx = x1 - x2; 329 | sx = -1; 330 | } 331 | if (y2 >= y1) 332 | { 333 | dy = y2 - y1; 334 | sy = 1; 335 | } 336 | else 337 | { 338 | dy = y1 - y2; 339 | sy = -1; 340 | } 341 | dx2 = dx << 1; 342 | dy2 = dy << 1; 343 | if (dx >= dy) 344 | { 345 | // 346 | // X major line 347 | // 348 | err = dx - dy2; 349 | dd2 = dx2 - dy2; 350 | while (x1!= x2) 351 | { 352 | oppix(x1, y1); 353 | x1 += sx; 354 | if (err < 0) 355 | { 356 | err += dd2; 357 | y1 += sy; 358 | } 359 | else 360 | err -= dy2; 361 | } 362 | } 363 | else 364 | { 365 | // 366 | // Y major line 367 | // 368 | err = dy - dx2; 369 | dd2 = dy2 - dx2; 370 | while (y1!= y2) 371 | { 372 | oppix(x1, y1); 373 | y1 += sy; 374 | if (err < 0) 375 | { 376 | err += dd2; 377 | x1 += sx; 378 | } 379 | else 380 | err -= dx2; 381 | } 382 | } 383 | oppix(x2, y2); 384 | } 385 | /* 386 | * Run main loop 387 | */ 388 | byte xTab = 2; 389 | byte yTab = 4; 390 | signed char xMove = 1; 391 | signed char yMove = -1; 392 | byte xLine = 42; 393 | byte yLine = 47; 394 | void loop(void) 395 | { 396 | byte i; 397 | 398 | if (vblank) // only update every frame 399 | { 400 | gotoxy(xTab + 1, yTab + 10); 401 | printstr(" "); 402 | xTab = xTab + xMove; 403 | if (xTab == 0 || xTab == 10) 404 | xMove = -xMove; 405 | yTab = yTab + yMove; 406 | if (yTab == 0 || yTab == 13 ) 407 | yMove = -yMove; 408 | gotoxy(xTab + 1, yTab + 10); 409 | printstr("Arduino!"); 410 | line(42, 20, xLine, yLine, xorpix); 411 | if (xLine == 77 && yLine == 20) 412 | { 413 | xLine = 42; 414 | yLine = 47; 415 | } 416 | else 417 | { 418 | if (++xLine > 77) 419 | { 420 | xLine = 77; 421 | yLine--; 422 | } 423 | } 424 | vblank=0; 425 | } 426 | } 427 | 428 | 429 | 430 | 431 | 432 | 433 | -------------------------------------------------------------------------------- /VideoSPI/chargen/chargen.h: -------------------------------------------------------------------------------- 1 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 2 | 0x7E, 0x81, 0xA5, 0x81, 0xBD, 0x99, 0x81, 0x7E, 3 | 0x7E, 0xFF, 0xDB, 0xFF, 0xC3, 0xE7, 0xFF, 0x7E, 4 | 0x6C, 0xFE, 0xFE, 0xFE, 0x7C, 0x38, 0x10, 0x00, 5 | 0x10, 0x38, 0x7C, 0xFE, 0x7C, 0x38, 0x10, 0x00, 6 | 0x38, 0x7C, 0x38, 0xFE, 0xFE, 0x7C, 0x38, 0x7C, 7 | 0x10, 0x10, 0x38, 0x7C, 0xFE, 0x7C, 0x38, 0x7C, 8 | 0x00, 0x00, 0x18, 0x3C, 0x3C, 0x18, 0x00, 0x00, 9 | 0xFF, 0xFF, 0xE7, 0xC3, 0xC3, 0xE7, 0xFF, 0xFF, 10 | 0x00, 0x3C, 0x66, 0x42, 0x42, 0x66, 0x3C, 0x00, 11 | 0xFF, 0xC3, 0x99, 0xBD, 0xBD, 0x99, 0xC3, 0xFF, 12 | 0x0F, 0x07, 0x0F, 0x7D, 0xCC, 0xCC, 0xCC, 0x78, 13 | 0x3C, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x7E, 0x18, 14 | 0x3F, 0x33, 0x3F, 0x30, 0x30, 0x70, 0xF0, 0xE0, 15 | 0x7F, 0x63, 0x7F, 0x63, 0x63, 0x67, 0xE6, 0xC0, 16 | 0x99, 0x5A, 0x3C, 0xE7, 0xE7, 0x3C, 0x5A, 0x99, 17 | 0x80, 0xE0, 0xF8, 0xFE, 0xF8, 0xE0, 0x80, 0x00, 18 | 0x02, 0x0E, 0x3E, 0xFE, 0x3E, 0x0E, 0x02, 0x00, 19 | 0x18, 0x3C, 0x7E, 0x18, 0x18, 0x7E, 0x3C, 0x18, 20 | 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x00, 21 | 0x7F, 0xDB, 0xDB, 0x7B, 0x1B, 0x1B, 0x1B, 0x00, 22 | 0x3E, 0x63, 0x38, 0x6C, 0x6C, 0x38, 0xCC, 0x78, 23 | 0x00, 0x00, 0x00, 0x00, 0x7E, 0x7E, 0x7E, 0x00, 24 | 0x18, 0x3C, 0x7E, 0x18, 0x7E, 0x3C, 0x18, 0xFF, 25 | 0x18, 0x3C, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x00, 26 | 0x18, 0x18, 0x18, 0x18, 0x7E, 0x3C, 0x18, 0x00, 27 | 0x00, 0x18, 0x0C, 0xFE, 0x0C, 0x18, 0x00, 0x00, 28 | 0x00, 0x30, 0x60, 0xFE, 0x60, 0x30, 0x00, 0x00, 29 | 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xFE, 0x00, 0x00, 30 | 0x00, 0x24, 0x66, 0xFF, 0x66, 0x24, 0x00, 0x00, 31 | 0x00, 0x18, 0x3C, 0x7E, 0xFF, 0xFF, 0x00, 0x00, 32 | 0x00, 0xFF, 0xFF, 0x7E, 0x3C, 0x18, 0x00, 0x00, 33 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 34 | 0x30, 0x78, 0x78, 0x30, 0x30, 0x00, 0x30, 0x00, 35 | 0x6C, 0x6C, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, 36 | 0x6C, 0x6C, 0xFE, 0x6C, 0xFE, 0x6C, 0x6C, 0x00, 37 | 0x30, 0x7C, 0xC0, 0x78, 0x0C, 0xF8, 0x30, 0x00, 38 | 0x00, 0xC6, 0xCC, 0x18, 0x30, 0x66, 0xC6, 0x00, 39 | 0x38, 0x6C, 0x38, 0x76, 0xDC, 0xCC, 0x76, 0x00, 40 | 0x60, 0x60, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 41 | 0x18, 0x30, 0x60, 0x60, 0x60, 0x30, 0x18, 0x00, 42 | 0x60, 0x30, 0x18, 0x18, 0x18, 0x30, 0x60, 0x00, 43 | 0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00, 44 | 0x00, 0x30, 0x30, 0xFC, 0x30, 0x30, 0x00, 0x00, 45 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x60, 46 | 0x00, 0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 47 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 48 | 0x06, 0x0C, 0x18, 0x30, 0x60, 0xC0, 0x80, 0x00, 49 | 0x7C, 0xC6, 0xCE, 0xDE, 0xF6, 0xE6, 0x7C, 0x00, 50 | 0x30, 0x70, 0x30, 0x30, 0x30, 0x30, 0xFC, 0x00, 51 | 0x78, 0xCC, 0x0C, 0x38, 0x60, 0xCC, 0xFC, 0x00, 52 | 0x78, 0xCC, 0x0C, 0x38, 0x0C, 0xCC, 0x78, 0x00, 53 | 0x1C, 0x3C, 0x6C, 0xCC, 0xFE, 0x0C, 0x1E, 0x00, 54 | 0xFC, 0xC0, 0xF8, 0x0C, 0x0C, 0xCC, 0x78, 0x00, 55 | 0x38, 0x60, 0xC0, 0xF8, 0xCC, 0xCC, 0x78, 0x00, 56 | 0xFC, 0xCC, 0x0C, 0x18, 0x30, 0x30, 0x30, 0x00, 57 | 0x78, 0xCC, 0xCC, 0x78, 0xCC, 0xCC, 0x78, 0x00, 58 | 0x78, 0xCC, 0xCC, 0x7C, 0x0C, 0x18, 0x70, 0x00, 59 | 0x00, 0x30, 0x30, 0x00, 0x00, 0x30, 0x30, 0x00, 60 | 0x00, 0x30, 0x30, 0x00, 0x00, 0x30, 0x30, 0x60, 61 | 0x18, 0x30, 0x60, 0xC0, 0x60, 0x30, 0x18, 0x00, 62 | 0x00, 0x00, 0xFC, 0x00, 0x00, 0xFC, 0x00, 0x00, 63 | 0x60, 0x30, 0x18, 0x0C, 0x18, 0x30, 0x60, 0x00, 64 | 0x78, 0xCC, 0x0C, 0x18, 0x30, 0x00, 0x30, 0x00, 65 | 0x7C, 0xC6, 0xDE, 0xDE, 0xDE, 0xC0, 0x78, 0x00, 66 | 0x30, 0x78, 0xCC, 0xCC, 0xFC, 0xCC, 0xCC, 0x00, 67 | 0xFC, 0x66, 0x66, 0x7C, 0x66, 0x66, 0xFC, 0x00, 68 | 0x3C, 0x66, 0xC0, 0xC0, 0xC0, 0x66, 0x3C, 0x00, 69 | 0xF8, 0x6C, 0x66, 0x66, 0x66, 0x6C, 0xF8, 0x00, 70 | 0xFE, 0x62, 0x68, 0x78, 0x68, 0x62, 0xFE, 0x00, 71 | 0xFE, 0x62, 0x68, 0x78, 0x68, 0x60, 0xF0, 0x00, 72 | 0x3C, 0x66, 0xC0, 0xC0, 0xCE, 0x66, 0x3E, 0x00, 73 | 0xCC, 0xCC, 0xCC, 0xFC, 0xCC, 0xCC, 0xCC, 0x00, 74 | 0x78, 0x30, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00, 75 | 0x1E, 0x0C, 0x0C, 0x0C, 0xCC, 0xCC, 0x78, 0x00, 76 | 0xE6, 0x66, 0x6C, 0x78, 0x6C, 0x66, 0xE6, 0x00, 77 | 0xF0, 0x60, 0x60, 0x60, 0x62, 0x66, 0xFE, 0x00, 78 | 0xC6, 0xEE, 0xFE, 0xFE, 0xD6, 0xC6, 0xC6, 0x00, 79 | 0xC6, 0xE6, 0xF6, 0xDE, 0xCE, 0xC6, 0xC6, 0x00, 80 | 0x38, 0x6C, 0xC6, 0xC6, 0xC6, 0x6C, 0x38, 0x00, 81 | 0xFC, 0x66, 0x66, 0x7C, 0x60, 0x60, 0xF0, 0x00, 82 | 0x78, 0xCC, 0xCC, 0xCC, 0xDC, 0x78, 0x1C, 0x00, 83 | 0xFC, 0x66, 0x66, 0x7C, 0x6C, 0x66, 0xE6, 0x00, 84 | 0x78, 0xCC, 0xE0, 0x70, 0x1C, 0xCC, 0x78, 0x00, 85 | 0xFC, 0xB4, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00, 86 | 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xFC, 0x00, 87 | 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0x78, 0x30, 0x00, 88 | 0xC6, 0xC6, 0xC6, 0xD6, 0xFE, 0xEE, 0xC6, 0x00, 89 | 0xC6, 0xC6, 0x6C, 0x38, 0x38, 0x6C, 0xC6, 0x00, 90 | 0xCC, 0xCC, 0xCC, 0x78, 0x30, 0x30, 0x78, 0x00, 91 | 0xFE, 0xC6, 0x8C, 0x18, 0x32, 0x66, 0xFE, 0x00, 92 | 0x78, 0x60, 0x60, 0x60, 0x60, 0x60, 0x78, 0x00, 93 | 0xC0, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x02, 0x00, 94 | 0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x78, 0x00, 95 | 0x10, 0x38, 0x6C, 0xC6, 0x00, 0x00, 0x00, 0x00, 96 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 97 | 0x30, 0x30, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 98 | 0x00, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0x76, 0x00, 99 | 0xE0, 0x60, 0x60, 0x7C, 0x66, 0x66, 0xDC, 0x00, 100 | 0x00, 0x00, 0x78, 0xCC, 0xC0, 0xCC, 0x78, 0x00, 101 | 0x1C, 0x0C, 0x0C, 0x7C, 0xCC, 0xCC, 0x76, 0x00, 102 | 0x00, 0x00, 0x78, 0xCC, 0xFC, 0xC0, 0x78, 0x00, 103 | 0x38, 0x6C, 0x60, 0xF0, 0x60, 0x60, 0xF0, 0x00, 104 | 0x00, 0x00, 0x76, 0xCC, 0xCC, 0x7C, 0x0C, 0xF8, 105 | 0xE0, 0x60, 0x6C, 0x76, 0x66, 0x66, 0xE6, 0x00, 106 | 0x30, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00, 107 | 0x0C, 0x00, 0x0C, 0x0C, 0x0C, 0xCC, 0xCC, 0x78, 108 | 0xE0, 0x60, 0x66, 0x6C, 0x78, 0x6C, 0xE6, 0x00, 109 | 0x70, 0x30, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00, 110 | 0x00, 0x00, 0xCC, 0xFE, 0xFE, 0xD6, 0xC6, 0x00, 111 | 0x00, 0x00, 0xF8, 0xCC, 0xCC, 0xCC, 0xCC, 0x00, 112 | 0x00, 0x00, 0x78, 0xCC, 0xCC, 0xCC, 0x78, 0x00, 113 | 0x00, 0x00, 0xDC, 0x66, 0x66, 0x7C, 0x60, 0xF0, 114 | 0x00, 0x00, 0x76, 0xCC, 0xCC, 0x7C, 0x0C, 0x1E, 115 | 0x00, 0x00, 0xDC, 0x76, 0x66, 0x60, 0xF0, 0x00, 116 | 0x00, 0x00, 0x7C, 0xC0, 0x78, 0x0C, 0xF8, 0x00, 117 | 0x10, 0x30, 0x7C, 0x30, 0x30, 0x34, 0x18, 0x00, 118 | 0x00, 0x00, 0xCC, 0xCC, 0xCC, 0xCC, 0x76, 0x00, 119 | 0x00, 0x00, 0xCC, 0xCC, 0xCC, 0x78, 0x30, 0x00, 120 | 0x00, 0x00, 0xC6, 0xD6, 0xFE, 0xFE, 0x6C, 0x00, 121 | 0x00, 0x00, 0xC6, 0x6C, 0x38, 0x6C, 0xC6, 0x00, 122 | 0x00, 0x00, 0xCC, 0xCC, 0xCC, 0x7C, 0x0C, 0xF8, 123 | 0x00, 0x00, 0xFC, 0x98, 0x30, 0x64, 0xFC, 0x00, 124 | 0x1C, 0x30, 0x30, 0xE0, 0x30, 0x30, 0x1C, 0x00, 125 | 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00, 126 | 0xE0, 0x30, 0x30, 0x1C, 0x30, 0x30, 0xE0, 0x00, 127 | 0x76, 0xDC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 128 | 0x00, 0x10, 0x38, 0x6C, 0xC6, 0xC6, 0xFE, 0x00, 129 | -------------------------------------------------------------------------------- /VideoSPI/chargen/chargen_reorder.h: -------------------------------------------------------------------------------- 1 | 0x00,0x7E,0x7E,0x6C,0x10,0x38,0x10,0x00,0xFF,0x00,0xFF,0x0F,0x3C,0x3F,0x7F,0x99,0x80,0x02,0x18,0x66,0x7F,0x3E,0x00,0x18,0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x6C,0x6C,0x30,0x00,0x38,0x60,0x18,0x60,0x00,0x00,0x00,0x00,0x00,0x06,0x7C,0x30,0x78,0x78,0x1C,0xFC,0x38,0xFC,0x78,0x78,0x00,0x00,0x18,0x00,0x60,0x78,0x7C,0x30,0xFC,0x3C,0xF8,0xFE,0xFE,0x3C,0xCC,0x78,0x1E,0xE6,0xF0,0xC6,0xC6,0x38,0xFC,0x78,0xFC,0x78,0xFC,0xCC,0xCC,0xC6,0xC6,0xCC,0xFE,0x78,0xC0,0x78,0x10,0x00,0x30,0x00,0xE0,0x00,0x1C,0x00,0x38,0x00,0xE0,0x30,0x0C,0xE0,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x18,0xE0,0x76,0x00, 2 | 0x00,0x81,0xFF,0xFE,0x38,0x7C,0x10,0x00,0xFF,0x3C,0xC3,0x07,0x66,0x33,0x63,0x5A,0xE0,0x0E,0x3C,0x66,0xDB,0x63,0x00,0x3C,0x3C,0x18,0x18,0x30,0x00,0x24,0x18,0xFF,0x00,0x78,0x6C,0x6C,0x7C,0xC6,0x6C,0x60,0x30,0x30,0x66,0x30,0x00,0x00,0x00,0x0C,0xC6,0x70,0xCC,0xCC,0x3C,0xC0,0x60,0xCC,0xCC,0xCC,0x30,0x30,0x30,0x00,0x30,0xCC,0xC6,0x78,0x66,0x66,0x6C,0x62,0x62,0x66,0xCC,0x30,0x0C,0x66,0x60,0xEE,0xE6,0x6C,0x66,0xCC,0x66,0xCC,0xB4,0xCC,0xCC,0xC6,0xC6,0xCC,0xC6,0x60,0x60,0x18,0x38,0x00,0x30,0x00,0x60,0x00,0x0C,0x00,0x6C,0x00,0x60,0x00,0x00,0x60,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x18,0x30,0xDC,0x10, 3 | 0x00,0xA5,0xDB,0xFE,0x7C,0x38,0x38,0x18,0xE7,0x66,0x99,0x0F,0x66,0x3F,0x7F,0x3C,0xF8,0x3E,0x7E,0x66,0xDB,0x38,0x00,0x7E,0x7E,0x18,0x0C,0x60,0xC0,0x66,0x3C,0xFF,0x00,0x78,0x6C,0xFE,0xC0,0xCC,0x38,0xC0,0x60,0x18,0x3C,0x30,0x00,0x00,0x00,0x18,0xCE,0x30,0x0C,0x0C,0x6C,0xF8,0xC0,0x0C,0xCC,0xCC,0x30,0x30,0x60,0xFC,0x18,0x0C,0xDE,0xCC,0x66,0xC0,0x66,0x68,0x68,0xC0,0xCC,0x30,0x0C,0x6C,0x60,0xFE,0xF6,0xC6,0x66,0xCC,0x66,0xE0,0x30,0xCC,0xCC,0xC6,0x6C,0xCC,0x8C,0x60,0x30,0x18,0x6C,0x00,0x18,0x78,0x60,0x78,0x0C,0x78,0x60,0x76,0x6C,0x70,0x0C,0x66,0x30,0xCC,0xF8,0x78,0xDC,0x76,0xDC,0x7C,0x7C,0xCC,0xCC,0xC6,0xC6,0xCC,0xFC,0x30,0x18,0x30,0x00,0x38, 4 | 0x00,0x81,0xFF,0xFE,0xFE,0xFE,0x7C,0x3C,0xC3,0x42,0xBD,0x7D,0x66,0x30,0x63,0xE7,0xFE,0xFE,0x18,0x66,0x7B,0x6C,0x00,0x18,0x18,0x18,0xFE,0xFE,0xC0,0xFF,0x7E,0x7E,0x00,0x30,0x00,0x6C,0x78,0x18,0x76,0x00,0x60,0x18,0xFF,0xFC,0x00,0xFC,0x00,0x30,0xDE,0x30,0x38,0x38,0xCC,0x0C,0xF8,0x18,0x78,0x7C,0x00,0x00,0xC0,0x00,0x0C,0x18,0xDE,0xCC,0x7C,0xC0,0x66,0x78,0x78,0xC0,0xFC,0x30,0x0C,0x78,0x60,0xFE,0xDE,0xC6,0x7C,0xCC,0x7C,0x70,0x30,0xCC,0xCC,0xD6,0x38,0x78,0x18,0x60,0x18,0x18,0xC6,0x00,0x00,0x0C,0x7C,0xCC,0x7C,0xCC,0xF0,0xCC,0x76,0x30,0x0C,0x6C,0x30,0xFE,0xCC,0xCC,0x66,0xCC,0x76,0xC0,0x30,0xCC,0xCC,0xD6,0x6C,0xCC,0x98,0xE0,0x00,0x1C,0x00,0x6C, 5 | 0x00,0xBD,0xC3,0x7C,0x7C,0xFE,0xFE,0x3C,0xC3,0x42,0xBD,0xCC,0x3C,0x30,0x63,0xE7,0xF8,0x3E,0x18,0x66,0x1B,0x6C,0x7E,0x7E,0x18,0x7E,0x0C,0x60,0xC0,0x66,0xFF,0x3C,0x00,0x30,0x00,0xFE,0x0C,0x30,0xDC,0x00,0x60,0x18,0x3C,0x30,0x00,0x00,0x00,0x60,0xF6,0x30,0x60,0x0C,0xFE,0x0C,0xCC,0x30,0xCC,0x0C,0x00,0x00,0x60,0x00,0x18,0x30,0xDE,0xFC,0x66,0xC0,0x66,0x68,0x68,0xCE,0xCC,0x30,0xCC,0x6C,0x62,0xD6,0xCE,0xC6,0x60,0xDC,0x6C,0x1C,0x30,0xCC,0xCC,0xFE,0x38,0x30,0x32,0x60,0x0C,0x18,0x00,0x00,0x00,0x7C,0x66,0xC0,0xCC,0xFC,0x60,0xCC,0x66,0x30,0x0C,0x78,0x30,0xFE,0xCC,0xCC,0x66,0xCC,0x66,0x78,0x30,0xCC,0xCC,0xFE,0x38,0xCC,0x30,0x30,0x18,0x30,0x00,0xC6, 6 | 0x00,0x99,0xE7,0x38,0x38,0x7C,0x7C,0x18,0xE7,0x66,0x99,0xCC,0x18,0x70,0x67,0x3C,0xE0,0x0E,0x7E,0x00,0x1B,0x38,0x7E,0x3C,0x18,0x3C,0x18,0x30,0xFE,0x24,0xFF,0x18,0x00,0x00,0x00,0x6C,0xF8,0x66,0xCC,0x00,0x30,0x30,0x66,0x30,0x30,0x00,0x30,0xC0,0xE6,0x30,0xCC,0xCC,0x0C,0xCC,0xCC,0x30,0xCC,0x18,0x30,0x30,0x30,0xFC,0x30,0x00,0xC0,0xCC,0x66,0x66,0x6C,0x62,0x60,0x66,0xCC,0x30,0xCC,0x66,0x66,0xC6,0xC6,0x6C,0x60,0x78,0x66,0xCC,0x30,0xCC,0x78,0xEE,0x6C,0x30,0x66,0x60,0x06,0x18,0x00,0x00,0x00,0xCC,0x66,0xCC,0xCC,0xC0,0x60,0x7C,0x66,0x30,0xCC,0x6C,0x30,0xD6,0xCC,0xCC,0x7C,0x7C,0x60,0x0C,0x34,0xCC,0x78,0xFE,0x6C,0x7C,0x64,0x30,0x18,0x30,0x00,0xC6, 7 | 0x00,0x81,0xFF,0x10,0x10,0x38,0x38,0x00,0xFF,0x3C,0xC3,0xCC,0x7E,0xF0,0xE6,0x5A,0x80,0x02,0x3C,0x66,0x1B,0xCC,0x7E,0x18,0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x6C,0x30,0xC6,0x76,0x00,0x18,0x60,0x00,0x00,0x30,0x00,0x30,0x80,0x7C,0xFC,0xFC,0x78,0x1E,0x78,0x78,0x30,0x78,0x70,0x30,0x30,0x18,0x00,0x60,0x30,0x78,0xCC,0xFC,0x3C,0xF8,0xFE,0xF0,0x3E,0xCC,0x78,0x78,0xE6,0xFE,0xC6,0xC6,0x38,0xF0,0x1C,0xE6,0x78,0x78,0xFC,0x30,0xC6,0xC6,0x78,0xFE,0x78,0x02,0x78,0x00,0x00,0x00,0x76,0xDC,0x78,0x76,0x78,0xF0,0x0C,0xE6,0x78,0xCC,0xE6,0x78,0xC6,0xCC,0x78,0x60,0x0C,0xF0,0xF8,0x18,0x76,0x30,0x6C,0xC6,0x0C,0xFC,0x1C,0x18,0xE0,0x00,0xFE, 8 | 0x00,0x7E,0x7E,0x00,0x00,0x7C,0x7C,0x00,0xFF,0x00,0xFF,0x78,0x18,0xE0,0xC0,0x99,0x00,0x00,0x18,0x00,0x00,0x78,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x00,0x00,0x78,0x00,0x00,0x00,0x00,0x00,0xF0,0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00, 9 | -------------------------------------------------------------------------------- /VideoSPI/chargen/reorderROM.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char **argv) 4 | { 5 | unsigned char charROM[1024]; 6 | int charIndex, charRow; 7 | 8 | for (charIndex = 0; charIndex < 1024; charIndex += 8) 9 | { 10 | if (scanf("%hhi,%hhi,%hhi,%hhi,%hhi,%hhi,%hhi,%hhi,\n", &charROM[charIndex], &charROM[charIndex+1], &charROM[charIndex+2], &charROM[charIndex+3], &charROM[charIndex+4], &charROM[charIndex+5], &charROM[charIndex+6], &charROM[charIndex+7]) != 8) 11 | { 12 | fprintf(stderr, "Error reading character ROM at row %i\n", charIndex / 8); 13 | return(1); 14 | } 15 | } 16 | for (charRow = 0; charRow < 8; charRow++) 17 | { 18 | for (charIndex = 0; charIndex < 128; charIndex++) 19 | { 20 | printf("0x%02X,", charROM[charIndex * 8 + charRow]); 21 | } 22 | printf("\n"); 23 | } 24 | } 25 | 26 | --------------------------------------------------------------------------------