kolleksjon av dokumenter og kode som blir brukt på Jokerspace i Valdres for å formiddle elektronisk musikk til et skapende milljø
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

harmonisk_improvisasjon.ino 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. const int Output = 1; // Can be 1 or 4
  2. // Cater for 16MHz, 8MHz, or 1MHz clock:
  3. const int Clock = ((F_CPU/1000000UL) == 16) ? 4 : ((F_CPU/1000000UL) == 8) ? 3 : 0;
  4. const uint8_t scale[] PROGMEM = {239,226,213,201,190,179,169,160,151,142,134,127};
  5. void note (int n, int octave) {
  6. int prescaler = 8 + Clock - (octave + n/12);
  7. if (prescaler<1 || prescaler>15 || octave==0) prescaler = 0;
  8. DDRB = (DDRB & ~(1<<Output)) | (prescaler != 0)<<Output;
  9. OCR1C = pgm_read_byte(&scale[n % 12]) - 1;
  10. GTCCR = (Output == 4)<<COM1B0;
  11. TCCR1 = 1<<CTC1 | (Output == 1)<<COM1A0 | prescaler<<CS10;
  12. }
  13. int cm[] = {0,3,7};
  14. int fm[] = {0,5,8};
  15. int g[] = {11,7,2,5,8};
  16. int member = 3;
  17. int note_length = 50;
  18. int n = 0;
  19. int octave = 1;
  20. int akkord = 0;
  21. unsigned long seconds = 0;
  22. unsigned long prev = 0;
  23. void setup() {
  24. // put your setup code here, to run once:
  25. //pinMode(1, OUTPUT);
  26. }
  27. void loop() {
  28. // put your main code here, to run repeatedly:
  29. note_length = random(30,70);
  30. octave = random(3,7);
  31. seconds = millis();
  32. seconds = seconds/1000;
  33. if (prev != seconds)
  34. akkord = random(0,3);
  35. prev = seconds;
  36. switch (akkord) {
  37. case 0: // cm
  38. member = random(3);
  39. n = cm[member];
  40. break;
  41. case 1: // fm
  42. member = random(3);
  43. n = fm[member];
  44. break;
  45. case 2: // g
  46. member = random(5);
  47. n = g[member];
  48. break;
  49. }
  50. note(n,octave);
  51. delay(note_length);
  52. }