int main(void) { adc_init();//initialize the LDR input DDRB = 0x00; DDRB |= (1<<PB4);//set led OUTPUT //PB2 input LDR ledBlink(5); // Retrieve, increment and store a randseed to eeprom - so the number sequence isn't the same each time! uint8_t randSeed = eeprom_read_byte ((uint8_t*)1); ++randSeed; eeprom_write_byte ((uint8_t*)1, randSeed); srand (randSeed); while (1 == 1) { raw = adc_read(1);//reading change in light value delay_ms(10); if ( raw < 100){ ledON( rng(2,3) , 100); pauseOFF(rng(3,10), 10); } } return 1; }
bool FramebufferInitialize() { fbRequest.size = sizeof(struct FramebufferRequest); fbRequest.bufferRequestResponseCode = 0; fbRequest.tag_setPd = 0x00048003; // tag ID fbRequest.size_setPd = 8; // value buffer size fbRequest.rr_setPd = 8; // req/res indicator fbRequest.width_setPd = kWidth; fbRequest.height_setPd = kHeight; fbRequest.tag_setVb = 0x00048004; fbRequest.size_setVb = 8; fbRequest.rr_setVb = 8; fbRequest.width_setVb = kWidth; fbRequest.height_setVb = kHeight; fbRequest.tag_setDepth = 0x00048005; fbRequest.size_setDepth = 4; fbRequest.rr_setDepth = 4; fbRequest.bitsPerPixel = 8; fbRequest.tag_setVo = 0x00048009; fbRequest.size_setVo = 8; fbRequest.rr_setVo = 8; fbRequest.frameBufferOffsetX = 0; fbRequest.frameBufferOffsetY = 0; fbRequest.tag_setPlt = 0x0004800B; fbRequest.size_setPlt = 0x28; fbRequest.rr_setPlt = 0x28; fbRequest.firstPltOffset = 0; // 0-255 fbRequest.pltLength = 8; // 1-256 // AABBGGRR fbRequest.color1 = 0x00000000; fbRequest.color2 = 0xFF0000FF; fbRequest.color3 = 0xFF00FF00; fbRequest.color4 = 0xFF0000FF; fbRequest.color5 = 0xFFFFFF00; fbRequest.color6 = 0xFFFF00FF; fbRequest.color7 = 0xFFFFFF00; fbRequest.color8 = 0xFFFFFFFF; fbRequest.tag_allocB = 0x00040001; fbRequest.size_allocB = 8; fbRequest.rr_allocB = 8; fbRequest.fbBaseAddress = 0; fbRequest.fbSize = 0; fbRequest.tag_end = 0; while (true) { MailboxWrite(((uint32_t)(&fbRequest) + MAIL_TAGS)); if (0 != fbRequest.fbBaseAddress) { ledBlink(3, kSlowInterval); break; } } return true; }
int main() { readUserSettings(); ledBlink(0); irqInit(); initClockIRQ(); fifoInit(); SetYtrigger(80); installWifiFIFO(); //installSoundFIFO(); installSystemFIFO(); installFeOSFIFO(); coopIrqSet(IRQ_VCOUNT, VCountHandler); irqEnable(IRQ_VBLANK | IRQ_VCOUNT | IRQ_NETWORK); setPowerButtonCB(powerButtonCB); while (!exitflag) { coopWaitForVBlank(); FeOS_VBlankFunc(); if (!(REG_KEYINPUT & (KEY_SELECT | KEY_START | KEY_L | KEY_R))) break; Wifi_Update(); } return 0; }
/* Exécute la demo ************************************************************ * --------------- ******************************************************************************/ void DemoPlay(void) { mmStart(0, MM_PLAY_LOOP); //CurrentPart = -1; //DemoAdvancePart(); CurrentPart = 0; DemoParts[0].init(); mmSetEventHandler(DemoParts[CurrentPart].sync); DemoParts[0].start_time = TimerMillis; while(1) { if(CurrentPart < NbParts) { DemoParts[CurrentPart].exec(TimerMillis - DemoParts[CurrentPart].start_time); if(DemoParts[CurrentPart].duration != 0) { if((TimerMillis - DemoParts[CurrentPart].start_time) >= DemoParts[CurrentPart].duration) { //DemoAdvancePart(); DemoParts[CurrentPart].deinit(); mmSetEventHandler(NULL); CurrentPart++; if(CurrentPart == NbParts) { ledBlink(PM_LED_BLINK); return; } DemoParts[CurrentPart].init(); mmSetEventHandler(DemoParts[CurrentPart].sync); DemoParts[CurrentPart].start_time = TimerMillis; } } } else { ledBlink(PM_LED_BLINK); return; } } }
uint32_t doAnimation(uint8_t animationNumber, uint8_t *animationFrameNumber) { switch(animationNumber) { case 0: return 0; break; case 1: return ledChaseUp(animationFrameNumber); // works break; case 2: return ledChaseDown(animationFrameNumber); // works break; case 3: return ledChaseUpDown(animationFrameNumber); // works break; case 4: return ledChaseAround(animationFrameNumber); // works break; case 5: return ledMarquee(animationFrameNumber); // works break; case 6: return ledDoubleUp(animationFrameNumber); // works break; case 7: return ledDoubleDown(animationFrameNumber); // works break; case 8: return ledLarsonTogether(animationFrameNumber); // works break; case 9: return ledLarsonOpposite(animationFrameNumber); // works break; case 10: return ledBlink(animationFrameNumber); // works break; case 11: return ledBlinkAlternate(animationFrameNumber); // works break; case 12: case 13: case 14: case 15: default: return 0; break; } }
//--------------------------------------------------------------------------------- int main() { //--------------------------------------------------------------------------------- // clear sound registers dmaFillWords(0, (void*)0x04000400, 0x100); REG_SOUNDCNT |= SOUND_ENABLE; writePowerManagement(PM_CONTROL_REG, ( readPowerManagement(PM_CONTROL_REG) & ~PM_SOUND_MUTE ) | PM_SOUND_AMP ); powerOn(POWER_SOUND); readUserSettings(); ledBlink(0); irqInit(); // Start the RTC tracking IRQ initClockIRQ(); fifoInit(); mmInstall(FIFO_MAXMOD); SetYtrigger(80); installWifiFIFO(); installSoundFIFO(); installSystemFIFO(); irqSet(IRQ_VCOUNT, VcountHandler); irqSet(IRQ_VBLANK, VblankHandler); irqEnable( IRQ_VBLANK | IRQ_VCOUNT | IRQ_NETWORK); setPowerButtonCB(powerButtonCB); // Keep the ARM7 mostly idle while (!exitflag) { if ( 0 == (REG_KEYINPUT & (KEY_SELECT | KEY_START | KEY_L | KEY_R))) { exitflag = true; } swiWaitForVBlank(); } return 0; }
/** * the interrupt to fire when the input pin is pulled up to 3v */ void signalIsr(void) { unsigned long long interruptTimeMs = getCurrentMilliseconds(); // determine whether this is rising edge or falling edge if(digitalRead(PIN_INPUT) == 1) { // rising edge interruptTimeMsRising = interruptTimeMs; return; } // Was there a preceding rising edge detected? if(interruptTimeMsRising == 0) { // No rising value, ignore return; } // else, falling edge unsigned long long intervalTimeMs = interruptTimeMs - interruptTimeMsRising; // reset, ready for next event interruptTimeMsRising = 0; printf("\n\nnew signal - interval was %llu\n", intervalTimeMs); if(intervalTimeMs < triggerInterval) { printf("ignoring, signal time was not long enough\n"); return; } // record the signal count to file fileRecordSignalCount(interruptTimeMs); // blink the LED to show we recorded the signal //piThreadCreate(ledSignalCounted); ledBlink(50); // attempt to submit the count file // disable - threads become unresponsive after a while. Rely on main loop call to processCountFile(); //processCountFile(); }
/** * init and run the application */ int main(int argc, char *argv[]) { if(argc < 2) { printf("signalCount: usage: signalCounter [endpoint] (trigger_interval_ms)\n"); return 1; } // store endpoint strcpy(endPointUrl, argv[1]); printf("Using [%s] as endpoint URL\n", endPointUrl); // store trigger interval, if we have one if(argc == 3) { char* p; // will be set to the "first invalid character" set by strtol errno = 0; triggerInterval = strtol(argv[2], &p, 10); if (*p != '\0' || errno != 0) { fprintf(stderr, "invalid trigger interval [%s]\n", argv[2]); return 1; } } printf("Using [%d] for trigger interval\n", triggerInterval); // init the wiringPi library if (wiringPiSetup () < 0) { fprintf(stderr, "Unable to setup wiringPi: %s\n", strerror (errno)); return 1 ; } // set up an interrupt on our input pin if (wiringPiISR(PIN_INPUT, INT_EDGE_BOTH, &signalIsr) < 0) { fprintf(stderr, "Unable to setup ISR: %s\n", strerror (errno)); return 1 ; } // configure the output pin for output. Output output output pinMode(PIN_OUTPUT, OUTPUT); pinMode(PIN_INPUT, INPUT); // pull the internal logic gate down to 0v - we don't want it floating around pullUpDnControl(PIN_INPUT, PUD_DOWN); // blink 3 times - we're ready to go ledBlink(300); delay(300); ledBlink(300); delay(300); ledBlink(300); // send a test signal count with the current timestamp fileRecordSignalCount(getCurrentMilliseconds()); printf("signalCount started\n"); for(;;) { delay(1000); // this thread will submit any count files that have not been sent printf("about to run cleanup thread\n"); processCountFile(); } return 0; }