/*! * \brief callback when new LED output is requested * \param ptr LED parameters */ void ledCallback(const phidgets::led_params::ConstPtr& ptr) { phidgets::led_params l = *ptr; for (int i = 0; i < (int)l.brightness.size(); i++) { // brightness in 0-100 range CPhidgetLED_setBrightness(phid, i, l.brightness[i]); } }
/** * Sets the brightness for a specific LED output * @note maximum brightness is 100, 0 is off. Can set this value to anything including and inbetween these values. */ void PhidgetLEDController::setBrightness( int index, double brightness ) { if ( !m_isValid || !m_LEDControl) { LOG_CRITICAL( "PhidgetLEDController::setBrightness(). ERROR LED board is not initialized. Call init first." ); return; } CPhidgetLED_setBrightness (m_LEDControl, index, brightness); }
int LED_simple() { int result, i; const char *err; //Declare an LED handle CPhidgetLEDHandle led = 0; //create the LED object CPhidgetLED_create(&led); //Set the handlers to be run when the device is plugged in or opened from software, unplugged or closed from software, or generates an error. CPhidget_set_OnAttach_Handler((CPhidgetHandle)led, AttachHandler, NULL); CPhidget_set_OnDetach_Handler((CPhidgetHandle)led, DetachHandler, NULL); CPhidget_set_OnError_Handler((CPhidgetHandle)led, ErrorHandler, NULL); //open the LED for device connections CPhidget_open((CPhidgetHandle)led, -1); //get the program to wait for an LED device to be attached printf("Waiting for LED to be attached...."); if((result = CPhidget_waitForAttachment((CPhidgetHandle)led, 10000))) { CPhidget_getErrorDescription(result, &err); printf("Problem waiting for attachment: %s\n", err); return 0; } //Display the properties of the attached LED device display_properties(led); printf("Press any key to continue\n"); getchar(); //turn on the leds one at a time. //This example assumes LED's plugged into locations 0-9 for(i = 0; i < 10; i++) { CPhidgetLED_setBrightness(led, i, 100); //maximum brightness is 100, 0 is off. Can set this value to anything including and inbetween these values. } printf("Press any key to continue\n"); getchar(); //turn off the LEDs one at a a time //This example assumes LED's plugged into locations 0-9 for(i = 0; i < 10; i++) { CPhidgetLED_setBrightness(led, i, 0); //maximum brightness is 100, 0 is off. Can set this value to anything including and inbetween these values. } printf("Press any key to end\n"); getchar(); //since user input has been read, this is a signal to terminate the program so we will close the phidget and delete the object we created printf("Closing...\n"); CPhidget_close((CPhidgetHandle)led); CPhidget_delete((CPhidgetHandle)led); //all done, exit return 0; }