D3N9: Demscene tribute on ChipKIT UNO32
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
D3N9: Old-Skool demoscene scroller for PIC32 | |
*/ | |
/* Kindly ripped from IOShield_OLED_Full_Demo */ | |
#include <IOShieldOled.h> | |
#define OLED IOShieldOledClass | |
OLED oled; | |
// Message to display. | |
char greetz[] = "*** Sine-wave text display for MPIDE/Uno32 *** Written by @indrora *** Greetz go out to ... Quelab ... Digilent ... Microchip ... Arduino ... ben_zen ... #gaygeeks ... #c *** Don't forget to floss! " ; | |
// Max columns | |
#define COL_MAX IOShieldOled.colMax | |
// Number of chars out of the message we can display at any one time. | |
#define NUM_CHARS 16 | |
// Macros. | |
#define MIDDLE_X (oled.colMax/2) | |
#define MIDDLE_Y (oled.rowMax/2) | |
// Times through the loop we've been | |
int ticks = 1; | |
// Floating-point version of the map function from Arduino | |
float mapf(float x, float in_min, float in_max, float out_min, float out_max) | |
{ | |
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; | |
} | |
void setup() { | |
// Init OLED. | |
oled.begin(); | |
pinMode(2, INPUT); // forward/backward. | |
pinMode(7, INPUT); // play/pause | |
pinMode(8, INPUT); // Display text on HIGH | |
pinMode(35, INPUT);// display starfield on HIGH | |
} | |
void loop() { | |
// Clear the buffer, since we're drawing a frame. | |
oled.clearBuffer(); | |
float phase = map(analogRead(A0), 0, 1023, 1,32); | |
if(digitalRead(8) == HIGH) | |
{ | |
// Draw text scroller. | |
oled.setDrawMode(OLED::modeSet); | |
for(int ix=0;ix<NUM_CHARS;ix++) | |
{ | |
float pos = min( ( ( MIDDLE_Y-4) + (sinf((float)(ticks+ix)/phase)*(float)(MIDDLE_Y)*0.75) ), 24 ) ; | |
// This is a glorious hack. | |
// c_char is ticks/phase + ix mod sizeof(greetz) -1 | |
// c_char now rotates gracefully through the string, looping when it needs to. | |
char c_char = *(greetz + ((ticks/(int)phase) + ix) % sizeof(greetz)-1 ); | |
oled.moveTo(8*ix,pos); | |
// putChar would, here, put it on the 4x16 grid. drawChar uses "graphic" characters. | |
oled.drawChar(c_char); | |
} | |
} | |
if(digitalRead(35) == HIGH) | |
{ | |
// Draw the starfield behind. | |
oled.setDrawMode(OLED::modeXor); | |
for(int ix = 0;ix<24; ix++) | |
{ | |
float x = mapf(ix,0,31 ,0,oled.colMax) ; | |
// Some fun math. | |
float y = mapf( sinf((cosf(2*ix)/24)*ticks), -1 , 1,0,oled.rowMax); | |
// This should mix things up a touch. | |
oled.moveTo( (int)(x*2) % (int)oled.colMax ,y ); | |
oled.drawPixel(); | |
} | |
} | |
// Now, what do we do /now/ | |
int dir = digitalRead(2); | |
int go = digitalRead(7); | |
if(go != LOW) | |
{ | |
if(dir != LOW) | |
ticks++; | |
else | |
ticks--; | |
} | |
delay(64); | |
// Pump the display. | |
oled.updateDisplay(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment