diff --git a/Fibomod2/Fibomod2.ino b/Fibomod2/Fibomod2.ino new file mode 100644 index 0000000..e0775e6 --- /dev/null +++ b/Fibomod2/Fibomod2.ino @@ -0,0 +1,63 @@ +// can fibomod make an interesting noise? + + +#include +#include + +Adafruit_MCP4728 mcp; + + +unsigned int fibo = 43; +unsigned int a = 0; +unsigned int b = 1; + +void setup() { + + cli(); + +//set timer1 interrupt at 1Hz + TCCR1A = 0;// set entire TCCR1A register to 0 + TCCR1B = 0;// same for TCCR1B + TCNT1 = 0;//initialize counter value to 0 + // set compare match register for 1hz increments + //OCR1A = 15624;// = (16*10^6) / (1*1024) - 1 (must be <65536) + //OCR1A = 7812;// = (16*10^6) / (1*1024) - 1 (must be <65536) + OCR1A = 1000; + // turn on CTC mode + TCCR1B |= (1 << WGM12); + // Set CS10 and CS12 bits for 1024 prescaler + TCCR1B |= (1 << CS12) | (1 << CS10); + // enable timer compare interrupt + TIMSK1 |= (1 << OCIE1A); + + sei(); + + + + Serial.begin(115200); + + if (!mcp.begin(0x64)) { + while (1) { + delay(100); + } + } + + mcp.setSpeed(800000L); + +} + + +ISR(TIMER1_COMPA_vect){ + fibo = analogRead(A0); + if( fibo < 3 ) + Serial.println(fibo); +} + + +void loop() { + unsigned int c = (a + b) % fibo; + a = b; + b = c; + mcp.fastWrite(a << 2, 0, 0, 0); +} +