0 Members and 1 Guest are viewing this topic.
#include "TimerOne.h"void setup(){ DDRB = 255; Timer1.initialize(16); // initialize timer1, and set a 1/2 second period Timer1.attachInterrupt(sound); // attaches callback() as a timer overflow interrupt Serial.begin(9600);}unsigned int counter[3] = {256,256,256};unsigned int wavelength[3] = {256,128,64};boolean gate[3] = {1,1,1};void sound(){ for (int i = 0; i<=2; i++){ // Cycle trough all the oscillators if (counter[i] -- == 0){ // If the oscillator ends half a period counter[i] = wavelength[i]; // Reset the counter to the wavelength if (gate[i]) // If the gate is on PORTB ^=1<<i; // Change the state of the oscillator pin } }}void loop(){ if (Serial.available()) wavelength[0] = Serial.read(); if (Serial.available()) wavelength[1] = Serial.read(); if (Serial.available()) wavelength[2] = Serial.read();}