int main(int argc, char* argv[]){ if(argc!=2){ printf("Usage is makeLEDC and one of:\n"); printf(" on, off, flash or status\n"); printf(" e.g. makeLED flash\n"); return 2; } printf("Starting the makeLED program\n"); printf("The current LED Path is: " LED3_PATH "\n"); // select whether command is on, off, flash or status if(strcmp(argv[1],"on")==0){ printf("Turning the LED on\n"); removeTrigger(); writeLED("/brightness", "1"); } else if (strcmp(argv[1],"off")==0){ printf("Turning the LED off\n"); removeTrigger(); writeLED("/brightness", "0"); } else if (strcmp(argv[1],"flash")==0){ printf("Flashing the LED\n"); writeLED("/trigger", "timer"); writeLED("/delay_on", "50"); writeLED("/delay_off", "50"); } else if (strcmp(argv[1],"status")==0){ FILE* fp; // see writeLED function below for description char fullFileName[100]; char line[80]; sprintf(fullFileName, LED3_PATH "/trigger"); fp = fopen(fullFileName, "rt"); //reading text this time while (fgets(line, 80, fp) != NULL){ printf("%s", line); } fclose(fp); } else{ printf("Invalid command!\n"); } printf("Finished the makeLED Program\n"); return 0; }
void PCA9685::setLEDDimmed(int ledNumber, byte amount) { // Amount from 0-100 (off-on) if (amount==0) { setLEDOff(ledNumber); } else if (amount>=100) { setLEDOn(ledNumber); } else { int randNumber = (int)random(4096); // Randomize the phaseshift to distribute load. Good idea? Hope so. writeLED(ledNumber, randNumber, (int)(amount*41+randNumber) & 0xFFF); } }
/***************************************************************************** * Main Function *****************************************************************************/ int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer /* Setup the ports for the 74HC164 chip */ P2DIR |= (CLOCK | DATA | MR); /* Make sure master reset is set high */ P2OUT |= MR; /* Make sure clock is initially low*/ P2OUT &= ~CLOCK; /* Setup the input button P1.3 */ P1DIR &= ~BUTTON; P1REN |= BUTTON; P1OUT |= BUTTON; // for(;;) // P2OUT ^= CLOCK; #if 1 unsigned int counter = 0; for (;;) { if ((P1IN & BUTTON) == 0) { writeLED(patternArray[counter]); if(++counter >= sizeof(patternArray)) { counter = 0; } } __delay_cycles(150000); } #endif return 0; }
void removeTrigger(){ writeLED("/trigger", "none"); }
void PCA9685::setLEDOff(int ledNumber) { writeLED(ledNumber, 0, 0x1000); }
void loop() { // read the potentiometer position colorVal = analogRead(potPin); powerVal = map(analogRead(pwrPotPin), 0, 1023, 0, 510); Serial.println(powerVal, DEC); buttonState = digitalRead(switchPin); // read input value and store it in val if (buttonState != lastButtonState) { if (buttonState == HIGH) { // check if the button is pressed switch(lightMode) { case 0: lightMode = 1; break; case 1: lightMode = 2; break; case 2: lightMode = 3; break; case 3: lightMode = 0; break; } } lastButtonState = buttonState; } if (lightMode == 0) { // turn light off analogWrite(ledRed, 0); analogWrite(ledGreen, 0); analogWrite(ledBlue, 0); } if (lightMode == 1) { // set fixed color setColor(); setPower(); writeLED(); } if (lightMode == 2) { // pulse fixed color if (millis() - previousMillis > interval) { // save the last time you blinked the LED previousMillis = millis(); setColor(); /* if (pulseState > powerVal) { pulseState = powerVal; } */ if (pulseDir == 0) { pulseState--; if (pulseState == 0) { pulseDir = 1; } } else { pulseState++; if (pulseState >= 255) { pulseDir = 0; } } redPwr = map(redPwr, 0, 255, 0, pulseState); bluePwr = map(bluePwr, 0, 255, 0, pulseState); greenPwr = map(greenPwr, 0, 255, 0, pulseState); writeLED(); } } if (lightMode == 3) { // randomsize colorNew and step colorPwr to it if (millis() - previousMillis > interval) { // save the last time you blinked the LED previousMillis = millis(); if (redPwr > redNew) { redPwr--; } if (redPwr < redNew) { redPwr++; } if (greenPwr > greenNew) { greenPwr--; } if (greenPwr < greenNew) { greenPwr++; } if (bluePwr > blueNew) { bluePwr--; } if (bluePwr < blueNew) { bluePwr++; } // If all Pwr match New get new colors if (redPwr == redNew) { if (greenPwr == greenNew) { if (bluePwr == blueNew) { redNew = random(254); greenNew = random(254); blueNew = random(254); } } } writeLED(); } } }