Skip to content

Instantly share code, notes, and snippets.

@gastonambrogi
Forked from AdamLoi/gist:10530101
Last active August 29, 2015 14:23
Show Gist options
  • Save gastonambrogi/4e93f70fe8adb4dff194 to your computer and use it in GitHub Desktop.
Save gastonambrogi/4e93f70fe8adb4dff194 to your computer and use it in GitHub Desktop.
//GRobotronics 29/3/2014
unsigned char i;
unsigned char j;
/*Port Definitions*/
int Max7219_pinCLK = 2;
int Max7219_pinCS = 1;
int Max7219_pinDIN = 0;
const int analogInPin = 3;
int sensorValue = 0;
unsigned char disp1[2][8]={
{0x00, 0x64, 0x62, 0x02, 0x02, 0x62, 0x64, 0x00},//0
{0x00, 0x22, 0x64, 0x04, 0x04, 0x64, 0x22, 0x00},//1
};
void Write_Max7219_byte(unsigned char DATA)
{
unsigned char i;
digitalWrite(Max7219_pinCS,LOW);
for(i=8;i>=1;i--)
{
digitalWrite(Max7219_pinCLK,LOW);
digitalWrite(Max7219_pinDIN,DATA&0x80);// Extracting a bit data
DATA = DATA<<1;
digitalWrite(Max7219_pinCLK,HIGH);
}
}
void Write_Max7219(unsigned char address,unsigned char dat)
{
digitalWrite(Max7219_pinCS,LOW);
Write_Max7219_byte(address); //address,code of LED
Write_Max7219_byte(dat); //data,figure on LED
digitalWrite(Max7219_pinCS,HIGH);
}
void Init_MAX7219(void)
{
Write_Max7219(0x09, 0x00);
Write_Max7219(0x0a, 0x03);
Write_Max7219(0x0b, 0x07);
Write_Max7219(0x0c, 0x01);
Write_Max7219(0x0f, 0x00);
}
void setup()
{
pinMode(Max7219_pinCLK,OUTPUT);
pinMode(Max7219_pinCS,OUTPUT);
pinMode(Max7219_pinDIN,OUTPUT);
delay(50);
Init_MAX7219();
}
void loop()
{
sensorValue = analogRead(analogInPin);
if(sensorValue<500) happy();
else sad();
}
void happy(){
for(i=1;i<9;i++){
Write_Max7219(i,disp1[0][i-1]);
}
}
void sad(){
for(j=1;j<9;j++){
Write_Max7219(j,disp1[1][j-1]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment