示例#1
0
//Initialize IO control ports of LEDS
void InitIOForLEDs()
{
	LED_DDR |= (1<<RED_LED);
	LED_DDR |= (1<<GREEN_LED);

	RED_LED_OFF();
	GREEN_LED_ON();
}
示例#2
0
int main(void)
{

  int i;

  MAMCR = 2;	// MAM functions fully enabled

  LED_INIT();
  YELLOW_LED_OFF();
  GREEN_LED_OFF();
  BUTTON_INIT();
  i=0;
  while (i<10)	{
    YELLOW_LED_ON();
    GREEN_LED_OFF();
    delay();
    YELLOW_LED_OFF();
    GREEN_LED_ON();
    delay();
    i++;
  }

  while (1)
    {
      if (BUTTTON1_OFF()) {
	YELLOW_LED_ON();
      }
      else {
	YELLOW_LED_OFF();
      }

      if (BUTTTON2_OFF())	{
	GREEN_LED_ON();
      }
      else {
	GREEN_LED_OFF();
      }
    }

  return 0; // never reached
}
示例#3
0
void MusicPlayer::controlLED()
{
  byte static flagOn = 1;
  int static count = 5000;
  if(playOrPause == 0)GREEN_LED_ON();
  else
    if(--count == 0)
    {
      count = 5000;
      if(flagOn == 1) 
      {
        GREEN_LED_ON();
        flagOn = 0;
      }
      else
      {
        GREEN_LED_OFF();
        flagOn = 1;
      }
    }
}
示例#4
0
void core3_main(void)
{
   // asm volatile ("mov sp,%0" : :"r" (ram3));
    
    while(1)
    {
        
        for(l=0; l < 500000; l++); //wait for some time
        GREEN_LED_ON();
        for(l=0; l < 500000; l++); //wait for some time
        GREEN_LED_OFF();
    }
}
示例#5
0
/** This function is called when the player is playing a song
 and there is free processor time. The basic task of this
 function is to implement the player user interface. */
void AvailableProcessorTime()
{

	do
	{
  		CheckKey();
  
 		 //IPODCommandProcess();
		 
		if(0 == playStop)
		{
			GREEN_LED_ON();
		}	
	}while(0 == playStop);
	
  	//do other things
	ControlLed();

}
示例#6
0
void ControlLed()
{
	static unsigned char greenOnOff = 1;
	
	
	if( 0 == greenFreq--)
	{
		greenOnOff = 1-greenOnOff;
		greenFreq = 5000;
	}
	if(greenOnOff)
	{
		GREEN_LED_ON();
	}
	else
	{
		GREEN_LED_OFF();
	}	

	//analogWrite(9,redPwm);
	
}
示例#7
0
void StackEventHandler(uint32 event,void *eventParam)
{
    
    switch(event)
	{
        
		case CYBLE_EVT_STACK_ON:
            //Starting Advertisement as soon as Stack is ON
             apiResult = CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST);
            if (apiResult == CYBLE_ERROR_OK)
            {
                printf ("Starting Advertisement\r\n");
            }
            else
            {
                printf ("Error Start Adv %d\r\n",apiResult);
            }
            break;
            
        case CYBLE_EVT_TIMEOUT:
         if( CYBLE_GAP_ADV_MODE_TO ==*(uint16*) eventParam)
            {
                printf ("Advertisement TimedOut\r\n");
                apiResult = CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST);
                if (apiResult != CYBLE_ERROR_OK)
                {
                    printf ("\nRestarting  Advertisement\r\n");
                }
            }
		
		case CYBLE_EVT_GATT_DISCONNECT_IND:
			/* Red LED Glows when device is disconnected */
            RED_LED_ON ();
            break;
            
        case CYBLE_EVT_GAP_DEVICE_DISCONNECTED:
            printf ("Disconnected \r\n");
            // Starting Advertisent again when there is disconnection
            apiResult = CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST);
            if (apiResult != CYBLE_ERROR_OK)
            {
                printf ("\nRestarting  Advertisement\r\n");
            }
            break;
            
			
		case CYBLE_EVT_GAP_DEVICE_CONNECTED:
            printf ("\n\r Connection Established \r\n");
            //Blue LED glows when device is connected
            BLUE_LED_ON ();
            break;

		
		case CYBLE_EVT_GAPP_ADVERTISEMENT_START_STOP:
         // This Event is received when advertisement is started or stopped.
            if (CyBle_GetState() == CYBLE_STATE_ADVERTISING)
            {
                printf("Advertising...\r\n");
                //Green LED Indicates that Advertisement is going on.
                GREEN_LED_ON();
            }
            else
            {
                RED_LED_ON();
                printf ("Advertisement Stopped \r\n");
                if (AddRequest == 1)
                {
                    AddRequest = 0;
                    // Adding the Device to whitelist
                    apiResult = CyBle_GapAddDeviceToWhiteList(&whitelistdeviceaddress); 
                                
                    if(apiResult == CYBLE_ERROR_INVALID_PARAMETER)
					{
						printf ("Adding to Whitelist Failed. Invalid parameter \r\n");
                    }
                    else if   (apiResult ==CYBLE_ERROR_INVALID_OPERATION)
                    {
                        printf ("Invalid Operation \r\n");
                    }
                    else if (apiResult ==CYBLE_ERROR_INSUFFICIENT_RESOURCES)
                    {
                      printf ("Adding to Whitelist Failed. List already full \r\n");
                    }
                    else if (apiResult ==CYBLE_ERROR_DEVICE_ALREADY_EXISTS)
                    {
                        printf ("Device Already exists \r\n");
                    }
                    else if (apiResult == CYBLE_ERROR_OK)
                    {
                        //Copying the address to the BackUp Array
                        whitelistdeviceaddressBackup[Index] = whitelistdeviceaddress; 
                        Index++;
                        printf ("Device Added to WhiteList\r\n");
                        printf ("Press A to Add or R to remove a from Whitelist \r\n");
                    }
                    
                    // Restarting the advertisement
                    apiResult = CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST);
                    if (apiResult == CYBLE_ERROR_OK)
                    {
                        printf ("Restarting Advertisement \r\n");
                        GREEN_LED_ON ();
                    }
                    else
                    {
                        printf ("Error Start Adv %d \r\n",apiResult);
                    }
                }
                if (DelRequest == 1)
                {
                    DelRequest = 0;
                    //Removing the Device from Whitelist
                    apiResult = CyBle_GapRemoveDeviceFromWhiteList 
                    (&whitelistdeviceaddressBackup[RemoveIndex]);
                    if (apiResult == CYBLE_ERROR_OK)
                    {
                        
                        uint8 j;
                        for (j = RemoveIndex; j<Index - 1; j++)
                        {
                            whitelistdeviceaddressBackup[j] = 
                            whitelistdeviceaddressBackup[j+1];
                        }
                        Index--;
                                                                                                                      
                        printf ("Device %d Removed from Whitelist\r\n",RemoveIndex + 1);
                        printf ("Press A to Add a Device or R to remove a device\r\n");
                    }
                    else if (apiResult == CYBLE_ERROR_NO_DEVICE_ENTITY)
                    {
                        printf ("No Such Device Exists. Press A to Add a Device or R to remove\r\n");
                    }
                    else 
                    {
                        printf ("Error: Operation cannot be performed");
                        printf ("Press A to Add a Device or R to remove\r\n");
                    }
                    //re-starting Advertisement
                    apiResult = CyBle_GappStartAdvertisement (CYBLE_ADVERTISING_FAST);
                    if (apiResult == CYBLE_ERROR_OK)
                    {
                        printf ("Restarting Advertisement\r\n");
                    }
                    else
                    {
                        printf ("Restarting Advertisement Failed\r\n");
                    }
                }
            }
            
		default:
			break;
	}
}