Procházet zdrojové kódy

move ugly code into library

master
Dom SP před 2 roky
rodič
revize
b666b75d70
3 změnil soubory, kde provedl 24 přidání a 14 odebrání
  1. +1
    -14
      AVR_code/harmonisk_improvisasjon/harmonisk_improvisasjon.ino
  2. +10
    -0
      AVR_code/harmonisk_improvisasjon/jokermusikk.cpp
  3. +13
    -0
      AVR_code/harmonisk_improvisasjon/jokermusikk.h

+ 1
- 14
AVR_code/harmonisk_improvisasjon/harmonisk_improvisasjon.ino Zobrazit soubor

@@ -1,16 +1,4 @@

const int Output = 1; // Can be 1 or 4
// Cater for 16MHz, 8MHz, or 1MHz clock:
const int Clock = ((F_CPU/1000000UL) == 16) ? 4 : ((F_CPU/1000000UL) == 8) ? 3 : 0;
const uint8_t scale[] PROGMEM = {239,226,213,201,190,179,169,160,151,142,134,127};
void note (int n, int octave) {
int prescaler = 8 + Clock - (octave + n/12);
if (prescaler<1 || prescaler>15 || octave==0) prescaler = 0;
DDRB = (DDRB & ~(1<<Output)) | (prescaler != 0)<<Output;
OCR1C = pgm_read_byte(&scale[n % 12]) - 1;
GTCCR = (Output == 4)<<COM1B0;
TCCR1 = 1<<CTC1 | (Output == 1)<<COM1A0 | prescaler<<CS10;
}
#include "jokermusikk.h"


int cm[] = {0,3,7};
@@ -26,7 +14,6 @@ unsigned long prev = 0;

void setup() {
// put your setup code here, to run once:
//pinMode(1, OUTPUT);
}

void loop() {

+ 10
- 0
AVR_code/harmonisk_improvisasjon/jokermusikk.cpp Zobrazit soubor

@@ -0,0 +1,10 @@
#include "jokermusikk.h"

void note (int n, int octave) {
int prescaler = 8 + Clock - (octave + n/12);
if (prescaler<1 || prescaler>15 || octave==0) prescaler = 0;
DDRB = (DDRB & ~(1<<Output)) | (prescaler != 0)<<Output;
OCR1C = pgm_read_byte(&scale[n % 12]) - 1;
GTCCR = (Output == 4)<<COM1B0;
TCCR1 = 1<<CTC1 | (Output == 1)<<COM1A0 | prescaler<<CS10;
}

+ 13
- 0
AVR_code/harmonisk_improvisasjon/jokermusikk.h Zobrazit soubor

@@ -0,0 +1,13 @@
#ifndef JOKERMUSIKK_H
#define JOKERMUSIKK_H
#include <Arduino.h>

const int Output = 1; // Can be 1 or 4
// Cater for 16MHz, 8MHz, or 1MHz clock:
const int Clock = ((F_CPU/1000000UL) == 16) ? 4 : ((F_CPU/1000000UL) == 8) ? 3 : 0;

const uint8_t scale[] PROGMEM = {239,226,213,201,190,179,169,160,151,142,134,127};

void note (int n, int octave);

#endif

Načítá se…
Zrušit
Uložit