Created
January 30, 2012 04:55
-
-
Save dnewcome/1702616 to your computer and use it in GitHub Desktop.
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
#include <LiquidCrystal.h> | |
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); | |
int offset = 0; | |
int sinetable[32]; | |
// Precomputed sine table taken from somewhere... | |
// can't find it now | |
void setupSintable() { | |
sinetable[0] = 127; | |
sinetable[1] = 152; | |
sinetable[2] = 176; | |
sinetable[3] = 198; | |
sinetable[4]=217; | |
sinetable[5]=233; | |
sinetable[6]=245; | |
sinetable[7]=252; | |
sinetable[8]=254; | |
sinetable[9]=252; | |
sinetable[10]=245; | |
sinetable[11]=233; | |
sinetable[12]=217; | |
sinetable[13]=198; | |
sinetable[14]=176; | |
sinetable[15]=152; | |
sinetable[16]=128; | |
sinetable[17]=103; | |
sinetable[18]=79; | |
sinetable[19]=57; | |
sinetable[20]=38; | |
sinetable[21]=22; | |
sinetable[22]=10; | |
sinetable[23]=3; | |
sinetable[24]=0; | |
sinetable[25]=3; | |
sinetable[26]=10; | |
sinetable[27]=22; | |
sinetable[28]=38; | |
sinetable[29]=57; | |
sinetable[30]=79; | |
sinetable[31]=103; | |
} | |
/** | |
* Set up the custom characters used for waveform | |
* display. | |
*/ | |
byte bar1[8] = { | |
B00000, | |
B00000, | |
B00000, | |
B00000, | |
B00000, | |
B00000, | |
B00000, | |
B11111, | |
}; | |
byte bar2[8] = { | |
B00000, | |
B00000, | |
B00000, | |
B00000, | |
B00000, | |
B00000, | |
B11111, | |
B00000, | |
}; | |
byte bar3[8] = { | |
B00000, | |
B00000, | |
B00000, | |
B00000, | |
B00000, | |
B11111, | |
B00000, | |
B00000, | |
}; | |
byte bar4[8] = { | |
B00000, | |
B00000, | |
B00000, | |
B00000, | |
B11111, | |
B00000, | |
B00000, | |
B00000, | |
}; | |
byte bar5[8] = { | |
B00000, | |
B00000, | |
B00000, | |
B11111, | |
B00000, | |
B00000, | |
B00000, | |
B00000, | |
}; | |
byte bar6[8] = { | |
B00000, | |
B00000, | |
B11111, | |
B00000, | |
B00000, | |
B00000, | |
B00000, | |
B00000, | |
}; | |
byte bar7[8] = { | |
B00000, | |
B11111, | |
B00000, | |
B00000, | |
B00000, | |
B00000, | |
B00000, | |
B00000, | |
}; | |
byte bar8[8] = { | |
B11111, | |
B00000, | |
B00000, | |
B00000, | |
B00000, | |
B00000, | |
B00000, | |
B00000, | |
}; | |
// values 0-15, pos 0-15 | |
void plotValue( int val, int pos ) { | |
if( val < 8 ) { | |
lcd.setCursor( pos, 1 ); | |
lcd.write( val ); | |
lcd.setCursor( pos, 0 ); | |
lcd.write( ' ' ); | |
} | |
else { | |
lcd.setCursor( pos, 0 ); | |
lcd.write( val - 8 ); | |
lcd.setCursor( pos, 1 ); | |
lcd.write( ' ' ); | |
} | |
} | |
void createCustomChars() { | |
lcd.createChar(0, bar1); | |
lcd.createChar(1, bar2); | |
lcd.createChar(2, bar3); | |
lcd.createChar(3, bar4); | |
lcd.createChar(4, bar5); | |
lcd.createChar(5, bar6); | |
lcd.createChar(6, bar7); | |
lcd.createChar(7, bar8); | |
} | |
void drawSin( int offset ) { | |
for( int x=0; x<16; x++ ) { | |
int val = sinetable[(2*x+offset)%32]/16; | |
plotValue( val, x ); | |
} | |
} | |
void setup() { | |
setupSintable(); | |
createCustomChars(); | |
lcd.begin(16, 2); | |
} | |
void loop() { | |
drawSin( offset ); | |
offset+=1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment