root / Ports / examples / glcdScope / glcdScope.pde
History | View | Annotate | Download (1.3 KB)
| 1 | //>>> The latest version of this code can be found at https://github.com/jcw/ !! |
|---|---|
| 2 | |
| 3 | // Very simple 100 KHz DSO scope, using the Graphics Board as display device. |
| 4 | // 2010-11-19 <jcw@equi4.com> http://opensource.org/licenses/mit-license.php |
| 5 | // $Id: glcdScope.pde 7763 2011-12-11 01:28:16Z jcw $ |
| 6 | |
| 7 | #include "ST7565.h" |
| 8 | |
| 9 | ST7565 glcd(14, 4, 17, 7); |
| 10 | byte samples[128]; |
| 11 | |
| 12 | static void sample() {
|
| 13 | for (byte i = 0; i < 128; ++i) {
|
| 14 | loop_until_bit_is_set(ADCSRA, ADIF); |
| 15 | bitSet(ADCSRA, ADIF); |
| 16 | samples[i] = ADCH; |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | void setup () {
|
| 21 | Serial.begin(57600); |
| 22 | Serial.println("\n[glcd_demo]");
|
| 23 | |
| 24 | glcd.st7565_init(); |
| 25 | glcd.st7565_command(CMD_DISPLAY_ON); |
| 26 | glcd.st7565_command(CMD_SET_ALLPTS_NORMAL); |
| 27 | glcd.st7565_set_brightness(0x15); |
| 28 | |
| 29 | analogRead(2); // run once to set up the ADC |
| 30 | |
| 31 | bitSet(ADMUX, ADLAR); // left adjust result |
| 32 | |
| 33 | // the ADC clock will determine the sample rate |
| 34 | ADCSRA = (ADCSRA & ~7) | 3; // values 2..7 are ok |
| 35 | |
| 36 | ADCSRB &= ~7; // free-running |
| 37 | bitSet(ADCSRA, ADATE); // auto trigger |
| 38 | bitSet(ADCSRA, ADSC); // start conversion |
| 39 | } |
| 40 | |
| 41 | void loop () {
|
| 42 | glcd.clear(); |
| 43 | |
| 44 | // sample quickly with interrupts disabled |
| 45 | cli(); |
| 46 | sample(); |
| 47 | sei(); |
| 48 | |
| 49 | for (byte i = 0; i < 128; ++i) |
| 50 | glcd.setpixel(i, 63 - samples[i] / 4, 1); |
| 51 | |
| 52 | glcd.display(); |
| 53 | delay(200); |
| 54 | } |