Skip to content

Instantly share code, notes, and snippets.

@tehn
Last active December 11, 2021 16:30
Show Gist options
  • Save tehn/1818cc86ec463436591915709d53d8c0 to your computer and use it in GitHub Desktop.
Save tehn/1818cc86ec463436591915709d53d8c0 to your computer and use it in GitHub Desktop.
grid test
// gcc test.c -lmonome
// 2nd arg is # of LEDs so you don't need to recompile so often
#include <stdlib.h>
#include <monome.h>
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <time.h>
unsigned int grid[16][16];
int quit = 0;
int c = 0;
long total = 0;
int DEL = 500000;
int LEDS = 16;
void handle_press(const monome_event_t *e, void *data) {
unsigned int x, y;
x = e->grid.x;
y = e->grid.y;
/* toggle the button */
grid[x][y] = !grid[x][y];
monome_led_set(e->monome, x, y, grid[x][y]);
quit = 1;
}
int main(int argc, char *argv[]) {
monome_t *monome;
if (argc < 2) {
printf("Usage %s device_path\n", argv[0]);
return 1;
}
if(argv[2]>0) LEDS = atoi(argv[2]);
int x, y;
for(x = 0; x < 16; x++)
for(y = 0; y < 16; y++) grid[x][y] = 0;
if( !(monome = monome_open(argv[1], "8000")) )
return -1;
clock_t t = clock();
monome_led_all(monome, 0);
monome_register_handler(monome, MONOME_BUTTON_DOWN, handle_press, NULL);
while(quit==0) {
t = clock();
for(int i=0;i<LEDS;i++) monome_led_level_set(monome, i%16, i/16, 0);
c++;
total = total + (clock() - t);
printf("time: %ld\n", total/c);
usleep(DEL);
for(int i=0;i<LEDS;i++) monome_led_level_set(monome, i%16, i/16, 3);
usleep(DEL);
monome_event_handle_next(monome);
}
//monome_event_loop(monome);
monome_close(monome);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment