// Each button randomly cycles through colors. // When a button is pressed, all of the buttons change to that color and pause // The pressed button(s) is/are lit up white while pressed // distributed from biboug.org. #define DATAOUT 11//MOSI (pin 7 of AD5206) #define DATAIN 12//MISO - not used, but part of builtin SPI #define SPICLOCK 13//sck (pin 8 of AD5206) #define ROWS 4 #define COLS 4 #define H 254 #define L 64 #define slavesel(x) ((x<6) ? 0 : 1) const byte rowpin[ROWS] = { 14,15,16,17}; const byte slaveselect[2] = { 10, 18}; // The pot register numbers for each of the red, green, and blue channels const byte red[4] = { 5, 2, 7, 8}; const byte green[4] = { 3, 0, 6, 11}; const byte blue[4] = { 1, 4, 9, 10}; byte rGrid[ROWS][COLS] = { 0}; byte gGrid[ROWS][COLS] = { 0}; byte bGrid[ROWS][COLS] = { 0}; const byte buttonWrite[4] = { 2, 5, 3, 4}; //Pins for the Vin of the buttons const byte buttonRead[4] = { 6, 7, 9, 8}; //Pins for reading the state of the buttons boolean pressed[ROWS][COLS] = { 0}; byte trajectory[ROWS][COLS] = { 0}; unsigned long time; #define PAUSE 1000 // END DEFINITIONS, BEGIN PROGRAM char spi_transfer(volatile char data) { SPDR = data; // Start the transmission while (!(SPSR & (1< 10){ time = millis(); for(byte x = 0; x < ROWS; ++x){ for(byte y = 0; y < COLS; ++y){ rGrid[x][y] = constrain(rGrid[x][y] + ((trajectory[x][y] & B001 ) ? 1 : -1),L, H); gGrid[x][y] = constrain(gGrid[x][y] + ((trajectory[x][y] & B010 ) ? 1 : -1),L, H); bGrid[x][y] = constrain(bGrid[x][y] + ((trajectory[x][y] & B100 ) ? 1 : -1),L, H); if (rGrid[x][y] == ( (trajectory[x][y] & B001) ? H : L ) && gGrid[x][y] == ( (trajectory[x][y] & B010) ? H : L ) && bGrid[x][y] == ( (trajectory[x][y] & B100) ? H : L ) ) { trajectory[x][y] = random(1,8); } } } } } void on_press(byte r, byte c){ for(byte x = 0; x < ROWS; ++x){ for(byte y = 0; y < COLS; ++y){ rGrid[x][y] = rGrid[r][c]; bGrid[x][y] = bGrid[r][c]; gGrid[x][y] = gGrid[r][c]; } } } void on_release(byte r, byte c){ rGrid[r][c] = rGrid[(r+1) % ROWS][(c+1) % COLS]; gGrid[r][c] = gGrid[(r+1) % ROWS][(c+1) % COLS]; bGrid[r][c] = bGrid[(r+1) % ROWS][(c+1) % COLS]; } void while_pressed(byte r, byte c){ time = millis() + PAUSE; rGrid[r][c] = 255; gGrid[r][c] = 255; bGrid[r][c] = 255; } void while_released(byte r, byte c){ }