Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Shitty strobe light
- * kerai 2014
- */
- // duhh I'm dumb, changed to use reciprocal of the earlier BPM division thing, whatever
- //////
- ////// ARDUINO PART
- //////
- // the setup function runs once when you press reset or power the board
- void setup() {
- // initialize digital pin 13 as an output.
- pinMode(12, OUTPUT);
- Serial.begin(115200);
- }
- typedef unsigned long MicroCounter;
- MicroCounter delay_sync_time=0;
- MicroCounter delay_period=100;
- #define MICROSECONDS_IN_ONE_SECOND_F 1000000.f
- // the loop function runs over and over again forever
- void loop() {
- if(Serial.available()){
- byte bpm = Serial.read();
- Serial.print(bpm, DEC);
- Serial.println("bpm");
- float bpmf = (float) bpm;
- delay_period = (unsigned) MICROSECONDS_IN_ONE_SECOND_F * (60.f / bpmf);
- delay_sync_time = micros();
- }
- MicroCounter time = micros();
- MicroCounter delta = time - delay_sync_time;
- if(delta > delay_period){
- delay_sync_time += delta;
- digitalWrite(12,!digitalRead(12));
- }
- }
- //////
- ////// UNIX PART
- //////
- #include <stdio.h>
- #include <stdint.h>
- int main(void){
- fprintf(stderr, "Enter number: ");
- unsigned bpm=0;
- scanf("%u", &bpm);
- uint8_t byte_bpm = (uint8_t) bpm;
- fprintf(stderr, "Got %u, byte value %hhu\n", bpm, byte_bpm);
- fwrite(&byte_bpm,1,1,stdout);
- }
- //////
- ////// How to use
- //////
- /*
- Put code on arduino.
- Open up a shell, compile dec_number_to_bin.c
- ./dec_number_bin > /dev/ttyACM0
- Follow prompt, etc.
- Written drunk, it works somehow, you're on your own synchronising it to audio.*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement