forked from noyzelab/uMANIAC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uMANIAC-NANO-V5-PREALPHA.ino
1375 lines (1278 loc) · 33.4 KB
/
uMANIAC-NANO-V5-PREALPHA.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ****************************
// uMANIAC-V0.5 PRE_ALPHA!
// uMANIAC - generative sequencer music module for Arduino with a cellular automata core
// NANO + cheap OLED - GATE OUTPUTS VERSION - this version is a simple example 1D CA with 3 or 5 neighbours, that simply assigns 12 cells directly to drive gate outputs via the
// digital out pins. its aimed at experimenters / DIYers who want to get up and running with complex/chaotic/ordered/cyclic systems with
// a minumum of spend/circuitry..
//
// PLEASE NOTE: THIS IS A PRE_ALPHA RELEASE! THERES NOT A LOT IN THE WAY OF CODE COMMENTING 0R USER MANUAL!
// THIS WILL COME BUT IT TAKES TIME :) !
// ITS DESIGNED TO RUN ON A NANO, BUT IT CAN BE EASILY PORTED TO 32u4 e.g. MICRO, MEGA, DUE, TEENSY etc. just remember to sort the i/o asnd clock in pins properly
//
// Dave Burraston 2017
// www.noyzelab.com
// ****************************
// ANYONE WISHING TO CONTRIBUTE FINANCIALLY, OR OTHERWISE COLLABORATE ON THIS PROJECT PLEASE FEEL FREE TO EMAIL ME : noyzelab@gmail.com
// ****************************
#include <Wire.h>
//#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 12
Adafruit_SSD1306 display(OLED_RESET);
#define SSD1306_LCDHEIGHT 64
#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
// PIN ALLOCATIONS
// CLOCK IN = D2
// GATE OUTS = D3 to 11, & D13
// MODE ACTION = A1 [this is currently a switch, but I have allocated this on Analogue for future use i.e. possible to have multiple mode actions ..
// MODE POT = A0
// SUBMODE POT = A2
// k size = A3
// CA LENGTH = A6
// variable pot pin = A7
// NOTE : A4 & A5 are used by the OLED I2C bus, and D12 is the OLED reset pin, a possible variant is to instead use an I2C to LCD,
// which would free up D12 for mode action switch, and allow for A1 to be used as another analogue / CV input
// Analogue pins
const byte modepotpin = A0;
const byte modeactionpin = A1;
const byte submodepotpin = A2;
const byte ksizepotpin = A3;
const byte lengthpotpin = A6;
const byte varparam1pin = A7;
// Digital pins
const byte clockpin = 2;
// GATE OUTS = D3 to 11, & D13
byte ksize =5;
unsigned int Lsize = 10;
byte Lmin = 8;
const unsigned int maxLsize = 75; // maximum number of cells. u will need to keep an eye on this when u compile that u dont go over the RAM size, unless u are running on a DUE..
unsigned long rnum = 0xFF00FF00; // 0xcccccccc; // 0x0f0f0f0f; 0xFF00FF00;
byte elembank = 0;
byte rtabsize = 32; // NEEDS to be 32 for v2k5
byte rtab[32]; // e.g. = { .. 1,1,1,1, 0,0,0,0} NOTE THIS VIEW OF THE ARRAY is NOT in BINARY, it is REVERSED!!!
byte rtablkup = 0;
byte oldcells[maxLsize];
byte newcells[maxLsize];
unsigned int gens = 0;
byte mode = 2; // 0 = rand all, 1 = left shift, 2 = right shift, 3 = all off
byte submode = 0;
byte camodereset = 0; // 0 = unpressed , 1 = pressed , based on modeaction pin
// note for digital pullup i subtract 1 when reading switches for postitive logic in code for readability
byte penddir = 0;
unsigned long newseedcntr = 0;
unsigned long newrandseed;
byte firstpulse = 0;
unsigned int ksizepot, lengthpot, varparam1pot;
unsigned long insomute = 8;
byte gotclk = 0;
byte arbgatesassign = 0;
byte tmp1,tmp2;
// ***************************** SETUP ****************************
void setup(){
byte i;
display.begin(SSD1306_SWITCHCAPVCC, 0x3D); // initialize with the I2C addr 0x3D (for the 128x64)
// Clear the buffer.
display.clearDisplay();
//Serial.begin(9600); // ONLY USE THIS FOR TESTING. TURN SERIAL OFF FOR FASTER CLOCKING VIA THE CLOCK IN ON PIN 2
//Serial.println();
//Serial.println("uMANIAC in setup... oled version");
//Serial.println();
// ALLOCATE PINS
pinMode(modeactionpin, INPUT_PULLUP); // mode action input
// set up pins 3 to 11 for cell gate outputs
for (i = 3; i < 12; i = i + 1)
{
pinMode(i, OUTPUT);
}
pinMode(13,OUTPUT); // cell 9 pin
clearca();
oldcells[9] = 1;
ruleinit();
gens =0;
// digital pin 2 = clock in for interrupt!!!!!
attachInterrupt(0, castep, RISING); // NANO/UNO
//attachInterrupt(2, castep, RISING); // 2 = Teensy LC
//attachInterrupt(digitalPinToInterrupt(clockpin), castep, RISING); // 7 = MICRO / LEONARDO
}
// ***************************** end SETUP ****************************
// ********* MAIN LOOP *********
void loop(){
byte i;
// READING INPUTS ***************************
mode = analogRead(modepotpin)/64;
submode = analogRead(submodepotpin)/64;
camodereset = 1-digitalRead(modeactionpin);
lengthpot = analogRead(lengthpotpin)/4;
lengthpot=map(lengthpot,0,255,1,maxLsize);
ksizepot = analogRead(ksizepotpin)/256;
elembank = analogRead(ksizepotpin)/128; // this gets 8 bank numbers for the elementary manual selek
varparam1pot = analogRead(varparam1pin); // insomniac mutatation multiplier etc
// END READING INPUTS ***************************
processinputs(); // PROCESS INPUTS ***************************
// ********************SECTION FOR TESTING WITHOUT EXT CLOCK. COMMENT OUT WHEN USING CLOCK IN ****************
// RUN CA ALGORITHM
//delay(250);
//castep();
// ******************** END _ SECTION FOR TESTING WITHOUT EXT CLOCK. COMMENT OUT WHEN USING CLOCK IN ****************
// DISPLAY ROUTINES
// SET OUTPUS OR ANY VAR NEED SETTING ???
// incremenmnt or twiddle seed cntr
newseedcntr = newseedcntr + 1UL;
if (newseedcntr > 4294000UL)
{
newseedcntr = 0;
newrandseed = millis();
randomSeed(newrandseed);
}
// ** DISPLAY INFO TO OLED / serial
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(32,0); // DISPLAY RULE NUM
switch (ksize)
{
case 3:
//display.setCursor(96,0);
display.print(byte(rnum),HEX);
display.print(" : ");
display.print(byte(rnum));
break;
case 4:
//display.setCursor(64,0);
display.print(" ");
display.print(word(rnum),HEX);
break;
case 5:
//display.setCursor(32,0);
display.print(rnum,HEX);
break;
default:
break;
} // end switch ksize
display.setCursor(32,16);
display.print("L");
display.print(Lsize);
display.setCursor(92,16);
display.print("K");
display.print(ksize);
display.setCursor(80,32);
display.print("G");
display.print(gens%1000);
display.setCursor(44,48); // position for mode/submode display
switch (mode)// MODE DISPLAY
{
case 0:
display.print("GM "); // GLOBAL MUTATE
mutatesubmodedisplay();
break;
case 1:
display.print("IG "); // INSOMNIAC GLOBAL MUTATOR
mutatesubmodedisplay();
display.setCursor(32,32);
display.print("I");
display.print(insomute);
break;
case 2:
display.print("LM "); // LOCAL MUTATE
mutatesubmodedisplay();
break;
case 3:
display.print("IL "); // INSOMNIAC LOCAL MUTATOR
mutatesubmodedisplay();
display.setCursor(32,32);
display.print("I");
display.print(insomute);
break;
case 4: //GLOCAL MUTATE
display.print("gM "); // GLOCAL MUTATE
glocalsubdisp();
break;
case 5:
display.print("Ig "); // INSOMNIAC GLOCAL MUTATOR
glocalsubdisp();
display.setCursor(32,32);
display.print("I");
display.print(insomute);
break;
case 6:
display.print("EL "); // ELEMENTARY k3
elemsubmodedisp();
display.setCursor(32,32);
display.print("B");
display.print(elembank*32);
break;
case 7:
display.print("E4 "); // 250 K4
elemsubmodedisp();
display.setCursor(32,32);
display.print("B");
display.print(elembank*32);
break;
case 8:
display.print("E5 "); // 250 K4
elemsubmodedisp();
display.setCursor(32,32);
display.print("B");
display.print(elembank*32);
break;
case 9:
display.print("DS "); // LEFT/DOWN SHIFT
break;
case 10:
display.print("US "); // RIGHT/UP SHIFT
break;
case 11:
display.print("PEN"); // PENDULUM
break;
case 12:
display.print("ON "); // ALL ON
break;
case 13:
display.print("OFF"); // ALL OFF
break;
case 14:
display.print("ARB"); // ARBITRARY CELL GATE SETUP
arbcelldisp();
break;
default:
break;
} // end switch case
// do any clock dependant stuff here that can't happen in the ISR
if (gotclk = 1)
{
cabardisplay();
//caspacetimedisplay(); // note this is for debugging only
gotclk = 0;
}
display.display();
}
// ********* end MAIN LOOP *********
void arbcelldisp()
{
switch (submode) // SUBMODE DISPLAY
{
case 0:
display.print("ACBC");
break;
case 1:
display.print("ARBC");
break;
case 2:
display.print("ACBR");
break;
case 3:
display.print("ARBR");
break;
case 4:
display.print("AGBR");
break;
case 5:
display.print("GCTR");
break;
default:
break;
} // end switch case submode
}
void mutatesubmodedisplay()
{
switch (submode) // SUBMODE DISPLAY
{
case 0:
display.print("_RCL");
break;
case 1:
display.print("_R__");
break;
case 2:
display.print("__C_");
break;
case 3:
display.print("___L");
break;
case 4:
display.print("_RC_");
break;
case 5:
display.print("_R_L");
break;
case 6:
display.print("__CL");
break;
case 7:
display.print("KRCL");
break;
case 8:
display.print("KR__");
break;
case 9:
display.print("K_C_");
break;
case 10:
display.print("K__L");
break;
case 11:
display.print("KRC_");
break;
case 12:
display.print("KR_L");
break;
case 13:
display.print("K_CL");
break;
case 14:
display.print("K___");
break;
case 15:
display.print("LM/2");
break;
default:
break;
} // end switch case submode
}
void glocalsubdisp()
{
switch (submode) // SUBMODE DISPLAY
{
case 0:
display.print("_R__");
break;
case 1:
display.print("KRCL");
break;
case 2:
display.print("_r__");
break;
case 3:
display.print("Krcl");
break;
case 4:
display.print("__CL");
break;
case 5:
display.print("__C_");
break;
case 6:
display.print("___L");
break;
case 7:
display.print("__cl");
break;
case 8:
display.print("__c_");
break;
case 9:
display.print("___l");
break;
case 10:
display.print("FST1");
break;
case 11:
display.print("L+1");
break;
case 12:
display.print("L-1");
break;
case 13:
display.print("L+10");
break;
case 14:
display.print("L-10");
break;
case 15:
display.print("LM/2");
break;
default:
break;
} // end switch case submode GLOCAL MUTATE
}
void elemsubmodedisp()
{
switch (submode) // SUBMODE DISPLAY
{
case 0:
display.print("CL");
break;
case 1:
display.print("C_");
break;
case 2:
display.print("_L");
break;
case 3:
display.print("END1");
break;
case 4:
display.print("FST1");
break;
case 5:
display.print("L+1");
break;
case 6:
display.print("L-1");
break;
case 7:
display.print("LMAX");
break;
case 8:
display.print("LMIN");
break;
case 9:
display.print("L+10");
break;
case 10:
display.print("L-10");
break;
case 11:
display.print("LM/2");
break;
default:
break;
} // end switch case submode
}
void processinputs()
{
switch (mode)
{
case 0:
globalmutate();
break;
case 1:
insomniacglobalmutate();
break;
case 2:
localmutate();
break;
case 3:
insomniaclocalmutate();
break;
case 4:
glocalmutate();
break;
case 5:
insomniacglocalmutate();
break;
case 6:
ruleselekk3();
break;
case 7:
ruleselekk4();
break;
case 8:
ruleselekk5();
break;
case 9:
leftshift();
break;
case 10:
rightshift();
break;
case 11:
pendulum();
break;
case 12:
allon();
break;
case 13:
alloff();
break;
case 14:
arbgates();
break;
default:
break;
} // end switch case
// END PROCESS INPUTS ***************************
}
// GLOBAL MUTATE
void globalmutate()
{
if (camodereset == 1)
{
gens = 0;
globalmutatesubmode();
camodereset = 0; // reset the switch status
} // end if camodereset == 1
} // END GLOBAL MUTATE
void insomniacglobalmutate() // INSOMIAC MUTATOR
{
if (camodereset == 1)
{
camodereset = 0; // reset the switch status
insomute = random(1,varparam1pot/4);
gens=0;
}
if (gens >insomute-1) // do insomniac mutation submode
{
gens=0;
globalmutatesubmode();
} // do insomniac mutation submode
} // END INSOMIAC MUTATOR
void globalmutatesubmode()
{
switch (submode)
{
case 0: // rand rule, cells, size
ksize=map(ksizepot,0,3,3,5);
randR();
randC();
randL();
break;
case 1:
ksize=map(ksizepot,0,3,3,5);
randR(); // rand rule
break;
case 2:
ksize=map(ksizepot,0,3,3,5);
randC(); // rand cell
break;
case 3:
ksize=map(ksizepot,0,3,3,5);
randL(); // rand size
break;
case 4:
ksize=map(ksizepot,0,3,3,5);
randR();
randC();
break;
case 5:
ksize=map(ksizepot,0,3,3,5);
randR();
randL();
break;
case 6:
ksize=map(ksizepot,0,3,3,5);
randC();
randL();
break;
case 7: // rand K, rule, cells, size
ksize=random(3,6);
randR();
randC();
randL();
break;
case 8:
ksize=random(3,6);
randR(); // rand rule
break;
case 9:
ksize=random(3,6);
randC(); // rand cell
break;
case 10:
ksize=random(3,6);
randL(); // rand size
break;
case 11:
ksize=random(3,6);
randR();
randC();
break;
case 12:
ksize=random(3,6);
randR();
randL();
break;
case 13:
ksize=random(3,6);
randC();
randL();
break;
case 14:
ksize=random(3,6);
break;
case 15:
Lsize = maxLsize/2;
break;
default:
break;
} // end switch case submode
}
// LOCAL MUTATE
void localmutate()
{
if (camodereset == 1)
{
gens = 0;
localmutatesubmode();
camodereset = 0; // reset the switch status
} // end if camodereset == 1
} // END LOCAL MUTATE
void insomniaclocalmutate() // INSOMIAC MUTATOR
{
if (camodereset == 1)
{
camodereset = 0; // reset the switch status
insomute = random(1,varparam1pot/4);
gens=0;
}
if (gens >insomute-1) // do insomniac mutation submode
{
gens=0;
localmutatesubmode();
} // do insomniac mutation submode
} // END INSOMIAC MUTATOR
void localmutatesubmode()
{
switch (submode)
{
case 0: // local rand rule, cell, size
ksize=map(ksizepot,0,3,3,5);
localrandR();
localrandC();
localrandL();
break;
case 1: // local rand rule
ksize=map(ksizepot,0,3,3,5);
localrandR();
break;
case 2: // local rand cell
ksize=map(ksizepot,0,3,3,5);
localrandC();
break;
case 3: // local rand size
ksize=map(ksizepot,0,3,3,5);
localrandL();
break;
case 4: // local rand rule, cell
ksize=map(ksizepot,0,3,3,5);
localrandR();
localrandC();
break;
case 5: // local rand rule, size
ksize=map(ksizepot,0,3,3,5);
localrandR();
localrandL();
break;
case 6: // local rand cell, size
ksize=map(ksizepot,0,3,3,5);
localrandC();
localrandL();
break;
case 7: // rand K, rule, cell\, size
ksize=random(3,6);
localrandR();
localrandC();
localrandL();
break;
case 8: // rand K, rule,
ksize=random(3,6);
localrandR();
break;
case 9: // rand K, cell
ksize=random(3,6);
localrandC();
break;
case 10: // rand K, size
ksize=random(3,6);
localrandL();
break;
case 11: // rand K, rule, cell
ksize=random(3,6);
localrandR();
localrandC();
break;
case 12: // rand K, rule, size
ksize=random(3,6);
localrandR();
localrandL();
break;
case 13: // rand K, cell, size
ksize=random(3,6);
localrandC();
localrandL();
break;
case 14:
ksize=random(3,6);
break;
case 15:
Lsize = maxLsize/2;
break;
default:
break;
} // end switch case submode
}
// GLOCAL MUTATE
void glocalmutate()
{
if (camodereset == 1)
{
gens = 0;
glocalmutatesubmode();
camodereset = 0; // reset the switch status
} // end if camodereset == 1
} // END GLOCAL MUTATE
void insomniacglocalmutate() // INSOMIAC MUTATOR
{
if (camodereset == 1)
{
camodereset = 0; // reset the switch status
insomute = random(1,varparam1pot/4);
gens=0;
}
if (gens >insomute-1) // do insomniac mutation submode
{
gens=0;
glocalmutatesubmode();
} // do insomniac mutation submode
} // END INSOMIAC MUTATOR
void glocalmutatesubmode()
{
switch (submode)
{
case 0: // global rand rule
ksize=map(ksizepot,0,3,3,5);
randR();
break;
case 1:
ksize=random(3,6); // global rand ksize, rule, cells, size
randR();
randC();
randL();
break;
case 2:
ksize=map(ksizepot,0,3,3,5);
localrandR(); // local rand rule
break;
case 3: // local rand K, rule, cells, size
ksize=random(3,6);
localrandR();
localrandC();
localrandL();
break;
case 4: //global rand cells, size
ksize=map(ksizepot,0,3,3,5);
randC();
randL();
break;
case 5:// global rand cell
ksize=map(ksizepot,0,3,3,5);
randC();
break;
case 6: // global rand size
ksize=map(ksizepot,0,3,3,5);
randL();
break;
case 7: // local rand cell, size
ksize=map(ksizepot,0,3,3,5);
localrandC();
localrandL();
break;
case 8: // local rand cell
ksize=map(ksizepot,0,3,3,5);
localrandC();
break;
case 9: // local rand size
ksize=map(ksizepot,0,3,3,5);
localrandL();
break;
case 10:
clearca();
firstcellset();
break;
case 11:
Lsizeplus1();
break;
case 12:
Lsizeminus1();
break;
case 13:
Lsizeplus10();
break;
case 14:
Lsizeminus10();
break;
case 15:
Lsize = maxLsize/2;
break;
default:
break;
} // end switch case submode
}
void ruleselekk3() // 0 to 255 rule selek with a fixed ksize of 3, uses kpot to select banks of 32 rules
{
ksize=3;
rnum = varparam1pot/32 + (elembank*32);
ruleinit();
if (camodereset == 1)
{
camodereset = 0; // reset the switch status
elemsubmode();
gens=0;
} // end camode action switch
}
void ruleselekk4() // 0 to 255 rule selek with a fixed ksize of 4, uses kpot to select banks of 32 rules
{
ksize=4;
rnum = varparam1pot/32 + (elembank*32);
ruleinit();
if (camodereset == 1)
{
camodereset = 0; // reset the switch status
elemsubmode();
gens=0;
} // end camode action switch
}
void ruleselekk5() // 0 to 255 rule selek with a fixed ksize of 5, uses kpot to select banks of 32 rules
{
ksize=4;
rnum = varparam1pot/32 + (elembank*32);
ruleinit();
if (camodereset == 1)
{
camodereset = 0; // reset the switch status
elemsubmode();
gens=0;
} // end camode action switch
}
void elemsubmode()
{
switch (submode)
{
case 0: // rand cells, size
randC();
randL();
break;
case 1:
randC(); // rand cell
break;
case 2:
randL(); // rand size
break;
case 3:
clearca();
endcellset();
break;
case 4:
clearca();
firstcellset();
break;
case 5:
Lsizeplus1();
break;
case 6:
Lsizeminus1();
break;
case 7:
Lsize = maxLsize;
break;
case 8:
Lsize = Lmin;
break;
case 9:
Lsizeplus10();
break;
case 10:
Lsizeminus10();
break;
case 11:
Lsize = maxLsize/2;
break;
default:
break;
} // end switch case submode
}
void leftshift()
{
ksize=map(ksizepot,0,3,3,5);
if (ksize == 3)
{
rnum = 240;
}
else
{
rnum = 0xFF00FF00;
}
ruleinit();
if (camodereset == 1)
{
camodereset = 0; // reset the switch status
Lsize = 10;
clearca();
oldcells[9] = 1;
gens = 0;
}
}
void rightshift()
{
ksize=map(ksizepot,0,3,3,5);
if (ksize == 3)
{
rnum = 170;
}
else
{
rnum = 0xcccccccc;
}
ruleinit();
if (camodereset == 1)
{
camodereset = 0; // reset the switch status
Lsize = 10;
clearca();
oldcells[0] = 1;
gens = 0;
}
}
void pendulum()
{
if (camodereset == 1)
{
camodereset = 0; // reset the switch status
ksize=3;
rnum = 240;
ruleinit();
Lsize = 10;
penddir = 0;
clearca();
oldcells[9] = 1;
gens = 0;
}
if (gens >(Lsize-2))
{
if (penddir == 0)
{
rnum = 170;
ruleinit();
penddir = 1;
clearca();
oldcells[0] = 1;
}