Exemplo n.º 1
0
void main (void)
{
	unsigned char lastsw, led ;

	P1 =0xFF;
	ledOff();

	lastsw = getKey();
	
	for(;;)
	{
		if (( getKey() == KEYON ) && ( lastsw == KEYOFF) )
		{
			 if (led == 1)
			 {
			 	led = LIGHTOFF;
				ledOff();
				
			 }
			 else
			 {
			  	led = LIGHTON;
				ledOn();
			 }
		 }
	}
}
Exemplo n.º 2
0
static void appDataConf(NWK_DataReq_t *req)
{
  ledOff(LED_DATA);

  if (NWK_SUCCESS_STATUS == req->status)
  {
    if (!appNetworkStatus)
    {
      ledOn(LED_NETWORK);
      SYS_TimerStop(&appNetworkStatusTimer);
      appNetworkStatus = true;
    }
  }
  else
  {
    msg.sensors.light++;

    if (appNetworkStatus)
    {
      ledOff(LED_NETWORK);
      SYS_TimerStart(&appNetworkStatusTimer);
      appNetworkStatus = false;
    }
  }

  appState = APP_STATE_SENDING_DONE;
}
Exemplo n.º 3
0
void main (void)
{
	unsigned char led ;
													
	ledOff();							 // Set led off
	led = LED_OFF;
		
	for	(;;)
	{
		for (;getkey() == KEY_OFF;);	// Key is now off
		delayms(10);

		if (led == LED_OFF)				// key is now on
		{
			led = LED_ON;
			ledOn();
		}
		else
		{
			led = LED_OFF;
			ledOff();
		}
		for (;getkey() == KEY_ON;);		// key is now on
		delayms(10);					// key is now off

	}
}
Exemplo n.º 4
0
// Modulate the IR LED for the given period (usec) and at the duty cycle set.
//
// Args:
//   usec: The period of time to modulate the IR LED for, in microseconds.
// Returns:
//   Nr. of pulses actually sent.
//
// Note:
//   The ESP8266 has no good way to do hardware PWM, so we have to do it all
//   in software. There is a horrible kludge/brilliant hack to use the second
//   serial TX line to do fairly accurate hardware PWM, but it is only
//   available on a single specific GPIO and only available on some modules.
//   e.g. It's not available on the ESP-01 module.
//   Hence, for greater compatibility & choice, we don't use that method.
// Ref:
//   https://www.analysir.com/blog/2017/01/29/updated-esp8266-nodemcu-backdoor-upwm-hack-for-ir-signals/
uint16_t IRsend::mark(uint16_t usec) {
  // Handle the simple case of no required frequency modulation.
  if (!modulation || _dutycycle >= 100) {
    ledOn();
    _delayMicroseconds(usec);
    ledOff();
    return 1;
  }

  // Not simple, so do it assuming frequency modulation.
  uint16_t counter = 0;
  IRtimer usecTimer = IRtimer();
  // Cache the time taken so far. This saves us calling time, and we can be
  // assured that we can't have odd math problems. i.e. unsigned under/overflow.
  uint32_t elapsed = usecTimer.elapsed();

  while (elapsed < usec) {  // Loop until we've met/exceeded our required time.
    ledOn();
    // Calculate how long we should pulse on for.
    // e.g. Are we to close to the end of our requested mark time (usec)?
    _delayMicroseconds(std::min((uint32_t) onTimePeriod, usec - elapsed));
    ledOff();
    counter++;
    if (elapsed + onTimePeriod >= usec)
      return counter;  // LED is now off & we've passed our allotted time.
    // Wait for the lesser of the rest of the duty cycle, or the time remaining.
    _delayMicroseconds(std::min(usec - elapsed - onTimePeriod,
                                (uint32_t) offTimePeriod));
    elapsed = usecTimer.elapsed();  // Update & recache the actual elapsed time.
  }
  return counter;
}
Exemplo n.º 5
0
/* entry points ======================================================== */
int main(void)
{
	int i;

	initLeds();

	while(1)
	{
		ledOn(LED_D1_GPIO_PORT,LED_D1_GPIO_PIN);
		ledOn(LED_D2_GPIO_PORT,LED_D2_GPIO_PIN);
		ledOn(LED_D3_GPIO_PORT,LED_D3_GPIO_PIN);
		ledOn(LED_D4_GPIO_PORT,LED_D4_GPIO_PIN);

		for(i=0;i<0x500000;i++);

		ledOff(LED_D1_GPIO_PORT,LED_D1_GPIO_PIN);
		ledOff(LED_D2_GPIO_PORT,LED_D2_GPIO_PIN);
		ledOff(LED_D3_GPIO_PORT,LED_D3_GPIO_PIN);
		ledOff(LED_D4_GPIO_PORT,LED_D4_GPIO_PIN);

		for(i=0;i<0x500000;i++);

	}

}
Exemplo n.º 6
0
/*
 * Summary:     Signals whether this specific board is set to give a faulty result
 *              3 flashes with half-second interval;
 *              GREEN=>non-faulty, RED=>faulty.
 * Parameters:  u32 led status
 *              BODY_RGB_GREEN_PIN = green, BODY_RGB_RED_PIN = red
 * Return:      None.
 */
void
faultSignal(u32 STATUS_LED)
{
  bool LED_PIN_STATE[3] =
    { false }; // place-holder for remembering which LEDs were on

  for (u32 i = 0; i < 3; ++i)
    { // Preserve the state of the LED lights
      LED_PIN_STATE[i] = ledIsOn(LED_PIN[i]);
      ledOff(LED_PIN[i]); // Turn off the light
    }

  for (u32 j = 0; j < 3; ++j)
    { // Flash thrice if faulty or not
      ledOn(STATUS_LED);
      delay(FAULT_STATUS_PERIOD);

      ledOff(STATUS_LED);
      delay(FAULT_STATUS_PERIOD);
    }

  for (u32 k = 0; k < 3; ++k)
    if (LED_PIN_STATE[k])
      ledOn(LED_PIN[k]); // Restore the state of the LED lights

  return;
}
Exemplo n.º 7
0
Arquivo: main.c Projeto: atiselsts/osw
void appMain(void)
{
    uint16_t i;

    // ------------------------- serial number
    DPRINTF("Mote %#04x starting...\n", localAddress);

    // ------------------------- external flash
#if WRITE_TO_FLASH
    prepareExtFlash();
#endif

    // ------------------------- light sensors
    if (localAddress != 0x0796) {
        PRINT("init isl\n");
        islInit();
        islOn();
    } else {
        PRINT("init ads\n");
        adsInit();
        adsSelectInput(0);
    }

    // ------------------------- main loop
    mdelay(3000);
    DPRINTF("starting main loop...\n");
    for (i = 0; i < 6; ++i) {
        redLedToggle();
        mdelay(100);
    }
    ledOff();

    uint32_t nextDataReadTime = 0;
    uint32_t nextBlinkTime = 0;
    for (;;) {
        uint32_t now = getRealTime();
        if (timeAfter32(now, nextDataReadTime)) {
            if (getJiffies() < 300 * 1000ul ) {
                nextDataReadTime = now + DATA_INTERVAL_SMALL;
            } else {
                nextDataReadTime = now + DATA_INTERVAL;
            }
            DataPacket_t packet;
            readSensors(&packet);
#if PRINT_PACKET
            printPacket(&packet);
#endif
        }
        if (timeAfter32(now, nextBlinkTime)) {
            nextBlinkTime = now + BLINK_INTERVAL;
            ledOn();
            msleep(100);
            ledOff();
        }
        msleep(1000);
    }
}
void blink(void *pdata)
{
	(void)pdata;
	while (1) {
		ledOn();
		OSTimeDly(1);
		ledOff();
		OSTimeDly(29);
		ledOn();
		OSTimeDly(1);
		ledOff();
		OSTimeDly(219);
	}
}
Exemplo n.º 9
0
Arquivo: io.c Projeto: jtn0514/SNESoIP
void ledSignal(uint8_t times) {
    ledOff();

    while (times > 0) {
        ledToggleGreen();
        _delay_ms(100);
        ledToggleGreen();
        ledToggleRed();
        _delay_ms(100);
        ledToggleRed();
        times--;
    }

    ledOff();
}
Exemplo n.º 10
0
void readSensors(DataPacket_t *packet)
{
    PRINTF("reading sensors...\n");
    uint32_t start = getJiffies();

    ledOn();
    humidityOn();

    packet->timestamp = getUptime();
    if (!islRead(&packet->islLight, true)) {
        PRINT("islRead failed\n");
        packet->islLight = 0xffff;
    // } else {
    //     PRINT("islRead OK\n");
    }
    packet->internalVoltage = adcRead(ADC_INTERNAL_VOLTAGE);
    packet->internalTemperature = adcRead(ADC_INTERNAL_TEMPERATURE);
    packet->sht75Humidity = humidityRead();
    packet->sht75Temperature = temperatureRead();

    humidityOff();
    ledOff();

    uint32_t end = getJiffies();
    PRINTF("   time spent: %u ms\n", end - start);
}
Exemplo n.º 11
0
byte BlinkPlug::state () {
    byte saved = leds;
    ledOff(1+2);
    byte result = !digiRead() | (!digiRead2() << 1);
    ledOn(saved);
    return result;
}
Exemplo n.º 12
0
void toggleLed()
{
        static int state=0;
        if(state==0) ledOff();
        else ledOn();
        state^=0x01;
}
Exemplo n.º 13
0
/*
 * Handle note-on messages
 * Precondition: 1 <= channel <= 16, 0 <= pitch < 128, 0 <= velocity < 128
 */
void HandleNoteOn(byte channel, byte pitch, byte velocity)
{
  //If zero velocity, turn the note off
  if (velocity == 0) {
    HandleNoteOff(channel, pitch, velocity);
    return;
  }
  
  double freq = frequencyTable[pitch];
  if (useSerial) {
    //Print a message to Serial Monitor
    Serial.println("NOTE ON");
    Serial.println("Channel: " + String(channel) + ", Pitch: " + String(pitch) + ", Velocity: " + String(velocity));
    Serial.println("Computed Frequency: "+String(freq)+"Hz");
  }
  if (useLCD) {
    //Print a message to the LCD
    clearLCD();
    printToLCD(0,0,"On F="+String(freq)+"Hz");
    printToLCD(0,1,"P="+String(pitch)+", V="+String(velocity));
  }
  ledOff(); //just to be safe
  
  DueTimer timer = Timer.getAvailable();
  timer.attachInterrupt(blinkLED);
  timer.setFrequency(freq);
  timer.start();
  activeTimers[pitch] = timer;
}
Exemplo n.º 14
0
/* Toggle the state of an LED */
void ledToggle(Led_TypeDef led) {
    uint8_t curState = 0;
    
    curState = GPIO_ReadOutputDataBit(LED_PORT[led], LED_PIN[led]);

    if (curState) ledOff(led);
    else ledOn(led);
}
Exemplo n.º 15
0
inline static void ledRapidBlink(uint8_t times) {
	for(int i = 0; i < times; i++) {
		ledOn();
		delay(200);
		ledOff();
		delay(200);
	}
}
Exemplo n.º 16
0
Arquivo: main.c Projeto: atiselsts/osw
void appMain(void)
{
    PRINTF("Mote %#04x data...\n", localAddress);
    ledOn();
    prepareExtFlash();
    readExtFlash();
    //PRINTF("External flash is empty!\n");
    ledOff();
}
Exemplo n.º 17
0
void inIRQTimer(){
	#define CHK 10
	char channels[CHK] = {1,2,3,5,7,10,16,29,57,62};

	uint16_t s;
	static uint16_t n = CHK;

	if (n++ >= CHK)
		n = 0;


	//loggerWrite("\n\r",2);
	//loggerWrite("\n\r",2);

	s = spektrum[channels[n]] ;
	//loggerWrite("\n\r",2);
	//s /= FFT_N;
		
	if(s >= 1){
		if (s > 2){
			if (s > 4){
				if (s > 7){
					if (s > 10){
						if (s > 14){
							if ( s > 20){
								if (s > 30){
									if (s > 55){
										if ( s > 70){
											if (s > 100){
												if (s > 135){
													if (s > 155){
														if ( s > 180){
															s = 14;
														} else s = 13;
													} else s = 12;
												} else s = 11;
											} else s = 10;
										} else s = 9;
									} else s = 8;
								} else s = 7;
							} else s = 6;
						} else s = 5;
					} else s = 4;
				} else s = 3;
			} else s = 2;
		} else s = 1;
	} else s = 0;

					
	//for (m = 0; m < s; m++) loggerWrite("**",1);

	ledOff();
	setChannel(n);
	ledOn(s);


}
Exemplo n.º 18
0
main()
{
    ledInit();
    
    for (;;) {
        ledOn();
        delay(1000);
        ledOff();
        delay(1000);
    }
}
Exemplo n.º 19
0
void ColorSensor::setPassive() {
  // set to highest sensitivity with led off
  ledOff();
  writeRegister(CAP_RED, 0);
  writeRegister(CAP_GREEN, 0);
  writeRegister(CAP_BLUE, 0);
  writeRegister(CAP_CLEAR, 0);
  writeRegisterLong(INT_RED_LO, 4095);
  writeRegisterLong(INT_GREEN_LO, 4095);
  writeRegisterLong(INT_BLUE_LO, 4095);
  writeRegisterLong(INT_CLEAR_LO, 4095);
}
Exemplo n.º 20
0
Arquivo: main.c Projeto: atiselsts/osw
void readSensors(DataPacket_t *packet)
{
    DPRINTF("reading sensors...\n");

    ledOn();
    humidityOn();

    packet->timestamp = getJiffies();
    packet->sourceAddress = localAddress;
    packet->dataSeqnum = ++dataSeqnum;

    if (localAddress != 0x0796) {
        if (!islRead(&packet->islLight, true)) {
            PRINT("islRead failed\n");
            packet->islLight = 0xffff;
        }
        packet->sq100Light = 0xffff;
    } else {
        packet->islLight = 0xffff;
        if (!readAds(&packet->sq100Light)) {
            PRINT("readAdsRegister failed\n");
            packet->sq100Light = 0xffff;
        }
    }

    packet->internalVoltage = adcRead(ADC_INTERNAL_VOLTAGE);
    packet->internalTemperature = adcRead(ADC_INTERNAL_TEMPERATURE);

    DPRINT("read hum\n");
    packet->sht75Humidity = humidityRead();
    packet->sht75Temperature = temperatureRead();
    DPRINT("read done\n");

    packet->crc = crc16((uint8_t *) packet, sizeof(*packet) - 2);

#if WRITE_TO_FLASH
    if (extFlashAddress < EXT_FLASH_SIZE) {
        DPRINT("Writing to flash\n");
        extFlashWrite(extFlashAddress, packet, sizeof(*packet));
        DataPacket_t verifyRecord;
        memset(&verifyRecord, 0, sizeof(verifyRecord));
        extFlashRead(extFlashAddress, &verifyRecord, sizeof(verifyRecord));
        if (memcmp(packet, &verifyRecord, sizeof(verifyRecord))) {
            ASSERT("writing in flash failed!" && false);
        }
        extFlashAddress += sizeof(verifyRecord);
    }
#endif

    humidityOff();
    ledOff();
}
Exemplo n.º 21
0
int main(){
	uint16_t counter=0;
	PORTD = 0x08;
	DDRB |= 0x01; /*Enable LED*/
	_delay_ms(100);
	if((PIND & 0x08) != 0){
		PORTD = 0x00;
		ledOn();
		_delay_ms(100);
		ledOff();
		DDRB &= ~0x01;
		asm volatile("jmp 0x0000\n\t");
	}
Exemplo n.º 22
0
boolean ArdubiosLed::processImp(uint8_t ticks) {
  if (_id) {
    switch ( LED_STATE(_flags) ) {
      case Ardubios_LedStateOff:
        ledOff();
        break;
      case Ardubios_LedStateOn:
        ledOn();
        break;
      case Ardubios_LedStateBlinkSlow:
        if (ticks & 0x10) ledOn(); else ledOff();
        break;
      case Ardubios_LedStateBlinkFast:
        if (ticks & 0x04) ledOn(); else ledOff();
        break;
      case Ardubios_LedStateHeartbeat:
        if ((ticks & 0xFE) == 0x02) ledOn(); else ledOff();
        break;
    }
  }
  return false;
}
Exemplo n.º 23
0
void Logic::init(Adafruit_ILI9341* display, uint8_t pinLed) {
	_display = display;
	_pinLed = pinLed;
	// text display tests
	_display->setTextSize(1);
	_display->setTextColor(ILI9341_WHITE);
	_display->setCursor(0, 0);
	_display->println("Starting...");
	ledOff();
	_screen = new Panel(0, 0, _display->width(), _display->height());
	_bar = new BarGraph(2, 2, 60, 120, 6, 38, 55);
	_screen->addChild(*_bar);

}
Exemplo n.º 24
0
Arquivo: main.c Projeto: IECS/MansOS
//-------------------------------------------
//      Entry point for the application
//-------------------------------------------
void appMain(void)
{
    // Set packet reception handler (callback function)
    serialSetPacketReceiveHandle(PRINTF_SERIAL_ID, serialPacketReceived, buf, BUF_SIZE);
    ledOff();

    // Send Ping every second
    static uint_t counter = 1;
    while (1) {
        PRINTF("Ping #%i\n", counter++);
        ledToggle();
        mdelay(1000);
    }
}
Exemplo n.º 25
0
void IRQbspInit()
{
    //Enable all gpios
    RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN |
                    RCC_APB2ENR_IOPCEN | RCC_APB2ENR_IOPDEN |
                    RCC_APB2ENR_IOPEEN | RCC_APB2ENR_IOPFEN;
    _led::mode(Mode::OUTPUT_2MHz);// No need to be fast
    sdCardDetect::mode(Mode::INPUT_PULL_UP_DOWN);
    sdCardDetect::pullup();
    //Now wait 100ms
    ledOn();
    delayMs(100);
    ledOff();
    miosix::IRQserialInit();
}
Exemplo n.º 26
0
States body_ATTRACT(int dt, GameState& game)
{
  if((dt - ATTRACT_lastFrame) >= ATTRACT_MILLIS_PER_FRAME)
  {
    ATTRACT_lastFrame = dt;
    ledOff(ATTRACT_currentFrame);
    ++ATTRACT_currentFrame;
    if(ATTRACT_currentFrame > S12)
      ATTRACT_currentFrame = MIN_OUTPUT_PIN;
    ledOn(ATTRACT_currentFrame);
  }
  if(wasAnyButtonPressed())
    return INTRO;
  return ATTRACT;
}
Exemplo n.º 27
0
kaa_error_t kaa_client_esp8266_error(kaa_client_t *kaa_client)
{
    KAA_RETURN_IF_NIL(kaa_client, KAA_ERR_BADPARAM);

    kaa_error_t error_code = KAA_ERR_NONE;

    KAA_LOG_INFO(kaa_client->kaa_context->logger, KAA_ERR_NONE, "ESP8266 Error found, reset.... and restart.");

    error_code = kaa_client_channel_error(kaa_client);

    kaa_client->connection_state = KAA_CLIENT_ESP8266_STATE_UNINITED;

    ledOff();

    return error_code;
}
Exemplo n.º 28
0
void appMain(void)
{
    PRINTF("Mote %#04x data...\n", localAddress);
    ledOn();
    prepareExtFlash();
    readExtFlash();
    //PRINTF("External flash is empty!\n");

#if ERASE_ALL_AFTER
    PRINTF("erasing...\n");
    extFlashBulkErase();
#endif

    ledOff();
    PRINTF("done...\n");
}
Exemplo n.º 29
0
// Turn the pin (LED) off for a given time.
// Sends an IR space for the specified number of microseconds.
// A space is no output, so the PWM output is disabled.
//
// Args:
//   time: Time in microseconds (us).
void IRsend::space(uint32_t time) {
  ledOff();
  if (time == 0) return;
#ifndef UNIT_TEST
  // delayMicroseconds is only accurate to 16383us.
  // Ref: https://www.arduino.cc/en/Reference/delayMicroseconds
  if (time <= 16383) {
    delayMicroseconds(time);
  } else {
    // Invoke a delay(), where possible, to avoid triggering the WDT.
    delay(time / 1000UL);  // Delay for as many whole milliseconds as we can.
    // Delay the remaining sub-millisecond.
    delayMicroseconds(static_cast<uint16_t>(time % 1000UL));
  }
#endif
}
Exemplo n.º 30
0
void Snake::update() {
    byte nextIndex = (headIndex + 1) % length;

    //Serial.print("nextIndex: ");
// Serial.println(nextIndex);

    // Turn off the tail
    xyz tail = snakeParts[nextIndex];
    ledOff(tail.x, tail.y, tail.z);

    // Replace the tail with the head and turn it on
    xyz next = nextPart();
    snakeParts[nextIndex] = next;
    ledOn(next.x, next.y, next.z);

    headIndex = nextIndex;
}