public
Last active

D3N9: Demscene tribute on ChipKIT UNO32

  • Download Gist
D3N9.cpp
C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
/*
 
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();
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.