// Control the LED's. MbedResponse *NetCentricApp::ledCommand(MbedRequest *request) { DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); if (request->n > 0) led1 = request->args[0]; if (request->n > 1) led2 = request->args[1]; if (request->n > 2) led3 = request->args[2]; if (request->n > 3) led4 = request->args[3]; MbedResponse *r = new MbedResponse(); r->requestId = request->id; r->commandId = request->commandId; r->error = NO_ERROR; r->n = 4; r->values = new float[4]; r->values[0] = led1; r->values[1] = led2; r->values[2] = led3; r->values[3] = led4; return r; }
MbedResponse *NetCentricApp::rotateR(MbedRequest *request) { printf("---------------IK BEN HIER___________"); DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); if (request->n > 0) led1 = request->args[0]; if (request->n > 1) led2 = request->args[1]; if (request->n > 2) led3 = request->args[2]; if (request->n > 3) led4 = request->args[3]; MbedResponse *r = new MbedResponse(); r->requestId = request->id; r->commandId = request->commandId; r->error = NO_ERROR; r->n = 4; r->values = new float[4]; r->values[0] = led1; r->values[1] = led2; r->values[2] = led3; r->values[3] = led4; callServo(request->args[0]); return r; }
int main() { MBED_HOSTTEST_TIMEOUT(20); MBED_HOSTTEST_SELECT(stdio_auto); MBED_HOSTTEST_DESCRIPTION(stdio); MBED_HOSTTEST_START("MBED_2"); DigitalOut led1(LED1); DigitalOut led2(LED2); int value_int; notify_start(); // Just to sync with host test supervisor const char* PRINT_PATTERN = "MBED: Your value was: %d\r\n"; while (true) { // SCANF PRINTF family value_int = 0; led1 = 1; scanf("%d", &value_int); printf(PRINT_PATTERN, value_int); led1 = 0; // FSCANF, FPRINTF family value_int = 0; led2 = 1; fscanf(stdin, "%d", &value_int); fprintf(stdout, PRINT_PATTERN, value_int); led2 = 0; } }
void led(int i) { //if(i>99){_delay_ms(111);return;} long int k; for(k=0;k<255;k++){ led1(i/10);_delay_us(800); led2(i%10);_delay_us(800);} }
static void appTaskLED2Led(void *pdata) { DigitalOut led2(LED2); while (true) { OSTimeDlyHMSM(0,0,0,500); led2 = !led2; } }
void leds_state(int leds) { led1( ( leds & (1<<0) ) && (1<<0) ); led2( ( leds & (1<<1) ) && (1<<1) ); led3( ( leds & (1<<2) ) && (1<<2) ); led4( ( leds & (1<<3) ) && (1<<3) ); led5( ( leds & (1<<4) ) && (1<<4) ); led6( ( leds & (1<<5) ) && (1<<5) ); }
void tskLED2(CThread *p_thread, xHandle p_params) { CPin led2(LED_PIN_1); led2.output(); while( p_thread->isAlive() ) { if ( m_semButton.wait() ) { // wait for the semaphore led2.toggle(); } } }
int main(void) { //Hier wird alles initialisiert, dh Grundeinstellungen festgelegt init_Motor(); //Motor einstellen init_system_tick(); //System Tick einstellen init_drehzahlsensor(); //Drehzahlsensor einstellen init_leds(); //LEDs einstellen init_hupe(); //Hupe einstellen sei(); //Alle Interrupts einschalten while(1) //Alles innerhalb der while Schleife wird immer wieder wiederholt { if (~PINB & 0x01) //Wenn der invertierte Wert des ersten Bits in PINB 1 ist, dann (also wenn der Button gedrückt wird) { led1(AN); //Mach die LEDs 1 und 3 an led3(AN); m_r(255,0); //Und die Motoren mit Vollgas (255) in 2 Richtungen m_l(255,1); _delay_ms(500); //Warte 500 ms led1(AUS); //LEDs 1 und 3 aus, LEDs 2 und 4 an led3(AUS); led2(AN); led4(AN); m_r(255,1); //Richtungen ändern m_l(255,0); _delay_ms(500); //und wieder 500ms in die andere Richtung m_r(0,0); //Motoren aus m_l(0,0); led2(AUS); //Leds aus led4(AUS); hupe(AN); //Hupe an _delay_ms(1000); //1 s warten hupe(AUS); //Hupe aus _delay_ms(300); //300ms warten hupe(AN); //Hupe an _delay_ms(500); //warte 500 ms hupe(AUS); //Hupe aus } //wieder nach oben } }
int main(void) { DDRB |= _BV(PB6) | _BV(PB7); // LED outputs PORTB |= _BV(PB7) | _BV(PB6); DDRB |= _BV(PB2); // Enable Motors output DDRC |= _BV(PC1); // Enable LASER outout stop(); // This pulls the motor driver reset wdt_enable(WDTO_4S); muartInit(); mprintf(PSTR("#Power up!\n")); // Ensure that the motor drivers are properly initialized by holding them in reset while the power stabilizes. for (char i=0;i<10;i++) { _delay_ms(100); } run(); mprintf(PSTR("#Motor drivers and laser armed!\n")); led1(0); led2(0); char frame = 0; while(1) { if (!(frame & 15)) { mprintf(PSTR("OK\n")); } if (frame & 8) { led1(!(frame & 1)); } else { led2(!(frame & 1)); } _delay_ms(50); wdt_reset(); frame++; } }
void animation(void) { volatile int i; for(i = 50;i<ANIMATION_MAX;i+=15) { led1(ON); delay_ms(i); led2(ON); delay_ms(i); led3(ON); delay_ms(i); led4(ON); delay_ms(i); led1(OFF); delay_ms(i); led2(OFF); delay_ms(i); led3(OFF); delay_ms(i); led4(OFF); delay_ms(i); } }
void test_spdt() { //创建所需元器件 ngdc dc("dc1", 5); ngspdt spdt("spdt", ngspdt::status_throw1); ngresistor r1("1", 5); ngresistor r2("2", 5); ngled led1("led1"); ngled led2("led2"); ngground gnd; //创建接线,连接各元器件 ngline l1(dc.pos, spdt.pole); ngline l2(spdt.throw1, r1.p1); ngline l3(spdt.throw2, r2.p1); ngline l4(r1.p2, led1.pos); ngline l5(r2.p2, led2.pos); ngline l6(led1.neg, dc.neg); ngline l7(led2.neg, dc.neg); ngline l0(dc.neg, gnd.ground); //创建电路图,添加元器件、接线到电路图 schema sch; sch.AddDevices(&dc, &spdt, &r1, &r2, &led1, &led2, &gnd, 0); sch.AddLines(&l1, &l2, &l3, &l4, &l5, &l6, &l7, &l0, 0); //创建仿真对象,添加电路图,并开始暂态仿真 circuit cir(&sch); cir.Tran("1t", "1m", 0); do { Sleep(200); char ch = getchar(); switch (ch) { case 'a': cir.SwitchOver(&spdt); Sleep(200); break; case 'q': cir.Halt(); default: break; }; } while (cir.IsRunning()); //主程序线程,类似windows UI消息循环 }
virtual void run() { CPinINT irq1(P13); CPinINT irq2(P14); CPin led1(LED1); CPin led2(LED2); irq1.begin(); irq2.begin(); while(1) { if ( irq1.wait(0) ) { led1.invert(); } if ( irq2.wait(0) ) { led2.invert(); } } }
void GPSSensorUBX::DoSerialAGPS(void) { // Light PwmOut led1(LED1); PwmOut led2(LED2); led1.write(1.0); led2.write(1.0); bool gotSomething = false; while(1) { char c; if(debug_read(&c)) { DBG("got %c",c); gps.putc(c); gotSomething = true; } else if(gotSomething) { break; } } DBG("out"); led1.write(0.0); led2.write(0.0); }
void vBTaskFunction( void *pvParameters ) { Serial *usb=(Serial*)pvParameters; Led led2(LED2); portTickType lastTickTime; lastTickTime = xTaskGetTickCount (); for( ;; ) { led2.on(); vTaskDelayUntil (&lastTickTime, 50); led2.off(); usb->printf("** [B] TICK: %d\r\n",(int)lastTickTime); vTaskDelayUntil (&lastTickTime, 400); } }
static void appTaskLeds(void *pdata) { DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); /* Task main loop */ while (true) { if (led1Flashing) { led1 = !led1; } if (led2Flashing) { led2 = !led2; } if (led3Flashing) { led3 = !led3; } if (led4Flashing) { led4 = !led4; } OSTimeDlyHMSM(0,0,0,500); } }
int main (void) { ioport_set_pin_dir(IO_1,IOPORT_DIR_OUTPUT); ioport_set_pin_dir(IO_2,IOPORT_DIR_OUTPUT); ioport_set_pin_dir(IO_3,IOPORT_DIR_OUTPUT); ioport_set_pin_dir(IO_4,IOPORT_DIR_OUTPUT); ioport_set_pin_dir(IO_5,IOPORT_DIR_OUTPUT); ioport_set_pin_dir(IO_6,IOPORT_DIR_OUTPUT); ioport_set_pin_dir(IO_7,IOPORT_DIR_OUTPUT); ioport_set_pin_dir(IO_8,IOPORT_DIR_INPUT); init_octopus(); animation(); //Activate button interrupt pmic_init(); pmic_set_scheduling(PMIC_SCH_ROUND_ROBIN); PORTC.INTCTRL = 0x03; PORTC.INT0MASK = (1<<3); PORTC.PIN3CTRL |= (1<<1); cpu_irq_enable(); //Activate ZCD signal interruption cpu_irq_disable(); PORTD.INTCTRL = 0x03; PORTD.INT0MASK = (1<<5); PORTD.PIN5CTRL |= 0x01; cpu_irq_enable(); //Activate RTC rtc_init(); // pwm_ini(SERVO_0); // pwm_update(SERVO_0,0); // delay_ms(1000); // pwm_update(SERVO_0,500); // delay_ms(1000); // pwm_update(SERVO_0,1000); char aux; char aux2; for(;;) { printf("hello"); if(bluetooth_is_rx_complete()) { scanf("%1c",&aux); switch (aux) { case 'C': scanf("%1c",&aux); if (aux=='1') { led1(ON); ioport_set_pin_level(IO_1,ON); } else { led1(OFF); ioport_set_pin_level(IO_1,OFF); } break; case 'T': scanf("%1c",&aux); if (aux=='1') { led2(ON); ioport_set_pin_level(IO_2,ON); } else { led2(OFF); ioport_set_pin_level(IO_2,OFF); } break; case 'D': scanf("%i",&dimmer); RTC.COMP=dimmer; break; case 'O': scanf("%1c",&aux); scanf("%1c",&aux); scanf("%1c",&aux2); if(aux == '1') { if(aux2=='1') { led3(ON); ioport_set_pin_level(IO_3,ON); } else { led3(OFF); ioport_set_pin_level(IO_3,OFF); } } else { if(aux2=='1') { led4(ON); ioport_set_pin_level(IO_4,ON); } else { led4(OFF); ioport_set_pin_level(IO_4,OFF); } } break; } } } }
int main (void) { ioport_set_pin_dir(IO_1,IOPORT_DIR_OUTPUT); ioport_set_pin_dir(IO_2,IOPORT_DIR_OUTPUT); ioport_set_pin_dir(IO_3,IOPORT_DIR_OUTPUT); ioport_set_pin_dir(IO_4,IOPORT_DIR_OUTPUT); init_octopus(); initial_animation(); pwm_ini(SERVO_0); pwm_update(SERVO_0,0); delay_ms(1000); pwm_update(SERVO_0,500); delay_ms(1000); pwm_update(SERVO_0,1000); char aux; char aux2; int dimmer=0; for(;;) { if(bluetooth_is_rx_complete()) { scanf("%1c",&aux); switch (aux) { case 'C': scanf("%1c",&aux); if (aux=='1') { led1(ON); ioport_set_pin_level(IO_1,ON); } else { led1(OFF); ioport_set_pin_level(IO_1,OFF); } break; case 'T': scanf("%1c",&aux); if (aux=='1') { led2(ON); ioport_set_pin_level(IO_2,ON); } else { led2(OFF); ioport_set_pin_level(IO_2,OFF); } break; case 'D': scanf("%i",&dimmer); break; case 'O': scanf("%1c",&aux); scanf("%1c",&aux); scanf("%1c",&aux2); if(aux == '1') { if(aux2=='1') { led3(ON); ioport_set_pin_level(IO_3,ON); } else { led3(OFF); ioport_set_pin_level(IO_3,OFF); } } else { if(aux2=='1') { led4(ON); ioport_set_pin_level(IO_4,ON); } else { led4(OFF); ioport_set_pin_level(IO_4,OFF); } } break; } } dimmer=dimmer*10; pwm_update(SERVO_0,dimmer); } }
Animation SpectrumAnimationFactoryRGBBands::createSpectrumAnimation(unsigned int nLEDs, const std::vector<std::pair<double, double>>& spectrum, const ControlSettings& settings) const { double brightnessRed = 0.0; double brightnessGreen = 0.0; double brightnessBlue = 0.0; double amplifyFactor = settings.volumeTotal/1000.0; double amplifyFactorRed = settings.volumeRed/25.0; double amplifyFactorGreen = settings.volumeGreen/50.0; double amplifyFactorBlue = settings.volumeBlue/100.0; for (const auto& bin : spectrum) { double frequency = bin.first; double amplitude = bin.second; if (frequency > settings.freqRedMin && frequency < settings.freqRedMax) { brightnessRed += amplitude*amplifyFactor*amplifyFactorRed; } if (frequency > settings.freqGreenMin && frequency < settings.freqGreenMax) { brightnessGreen += amplitude*amplifyFactor*amplifyFactorGreen; } if (frequency > settings.freqBlueMin && frequency < settings.freqBlueMax) { brightnessBlue += amplitude*amplifyFactor*amplifyFactorBlue; } } Animation animation; Frame frame(nLEDs); int centreLedNr = nLEDs/2; // int maxRGB = std::max(brightnessBlue, std::max(brightnessRed, brightnessGreen)); // brightnessRed *= 255.0/maxRGB; // brightnessGreen *= 255.0/maxRGB; // brightnessBlue *= 255.0/maxRGB; for (int i = 0; i < centreLedNr; ++i) { int scaleFact = (i * 255) / centreLedNr; // int scaleFact = 0.0; int r = brightnessRed - scaleFact; int g = brightnessGreen - scaleFact; int b = brightnessBlue - scaleFact; if (r > 255) { r = 255; } if (g > 255) { g = 255; } if (b > 255) { b = 255; } if (r < 0) { r = 0; } if (g < 0) { g = 0; } if (b < 0) { b = 0; } int offSet = 0; int ledNr1 = (centreLedNr + i + 1 + offSet) % nLEDs; int ledNr2 = (centreLedNr - i + offSet) % nLEDs; LED led(ledNr1, Color(r, g, b)); frame.addLED(led); LED led2(ledNr2, Color(r, g, b)); frame.addLED(led2); } animation.addFrame(frame); return animation; }