//data display from right to left, from bottom to top, HIGH level display.
const uint8_t dispCLK = A5;
const uint8_t dispDAT = A4;
uint8_t dispBuffer[16];
void setPixel( uint8_t, uint8_t, bool );
void disp_Start();
void disp_Send(unsigned char send_data);
void disp_End();
void setup()
{
pinMode(dispCLK, OUTPUT);
pinMode(dispDAT, OUTPUT);
digitalWrite(dispCLK,LOW);
digitalWrite(dispCLK,LOW);
memset( dispBuffer, 0x00, sizeof( dispBuffer ) );
disp_Update();
}
void loop()
{
static uint8_t
currX=0,
currY=0,
lastX=0,
lastY=0;
static uint32_t
tPixel=0ul;
uint32_t
tNow = millis();
if( (tNow - tPixel) >= 250ul )
{
tPixel = tNow;
dispSetPixel( lastX, lastY, false );
currX++;
if( currX > 15 )
{
currX = 0;
currY++;
if( currY > 7 )
currY = 0;
}//if
dispSetPixel( currX, currY, true );
lastX = currX;
lastY = currY;
disp_Update();
}//if
}//loop
void disp_Update()
{
//set address++ mode
//not sure this needs to be done every update...
disp_Start();
disp_Send(0x40);
disp_End();
//send image buffer
disp_Start();
disp_Send(0xC0);// set the row address
for( uint8_t idx=0; idx<16; idx++ )
disp_Send( dispBuffer[idx] );
disp_End();
//brightness
//not sure this needs to be done every update...
disp_Start();
disp_Send(0x8A);// set the brightness display
disp_End();
}//disp_Update
void disp_Start()
{
//send start condition
digitalWrite(dispCLK,LOW);
delayMicroseconds(3);
digitalWrite(dispDAT,HIGH);
delayMicroseconds(3);
digitalWrite(dispCLK,HIGH);
delayMicroseconds(3);
digitalWrite(dispDAT,LOW);
delayMicroseconds(3);
}//disp_Start
void disp_Send(uint8_t send_data)
{
//send a byte to the display; LSB first
for(uint8_t i=0; i<8; i++)
{
digitalWrite(dispCLK,LOW);
delayMicroseconds(3);
digitalWrite(dispDAT, (send_data & 0x01) ? HIGH : LOW );
delayMicroseconds(3);
digitalWrite(dispCLK,HIGH);
delayMicroseconds(3);
send_data = send_data >> 1;
}//for
}//disp_Send
void disp_End()
{
digitalWrite(dispCLK,LOW);
delayMicroseconds(3);
digitalWrite(dispDAT,LOW);
delayMicroseconds(3);
digitalWrite(dispCLK,HIGH);
delayMicroseconds(3);
digitalWrite(dispDAT,HIGH);
delayMicroseconds(3);
}//disp_End
void dispSetPixel( uint8_t x, uint8_t y, bool state )
{
//x and y are arbitrary
//for this exercise the matrix is set as:
//
// x=0 1 2 3 4 5 6 7 8 9 A B C D E F
// 0 o o o o o o o o o o o o o o o o
// 1 o o o o o o o o o o o o o o o o
// 2 o o o o o o o o o o o o o o o o
// 3 o o o o o o o o o o o o o o o o
// 4 o o o o o o o o o o o o o o o o
// 5 o o o o o o o o o o o o o o o o
// 6 o o o o o o o o o o o o o o o o
//y=7 o o o o o o o o o o o o o o o o
//
if( x > 15 || y > 7 )
return;
uint8_t mask = 1 << y;
if( state == true )
dispBuffer[x] |= mask;
else
dispBuffer[x] &= (mask ^ 0xff);
}//dispSetPixel