Example #1
0
void
Frame::addLED(const LED& led)
{
  if (led.getLEDnr() >= 0 && led.getLEDnr() < m_nLEDs)
  {
    m_leds[led.getLEDnr()] = led;
  }
}
Example #2
0
File: main.cpp Project: JJK801/Cosa
void setup()
{
  // Start the watchdog ticks and push time events
  Watchdog::begin(16, SLEEP_MODE_IDLE, Watchdog::push_timeout_events);

  // Start the built-in LED in alert mode
  static LED builtin;
  builtin.alert_mode();
}
Example #3
0
Circuit::Circuit(Console *_console) : console(_console), terminals(1000),
    outLedList(IO_COUNT), usedInput(IO_COUNT, false), usedOutput(IO_COUNT, false)
{
    QList<QGraphicsItem *> items = console->items();

    Wire *wire;
    LED *led;
    IC *ic;
    int i, j;

    for (auto it = items.begin(); it != items.end(); it++)
    {
        if ((wire = dynamic_cast<Wire *>(*it)))
        {
            i = _console->getOffset(wire->line().p1());
            j = _console->getOffset(wire->line().p2());
            if (terminals.join(i, j))
            {
                connections.push_back(Connection(i, j));
                wire->markRedundent(false);
            }
            else
                wire->markRedundent(true);
            if (i >= OUTPUT_OFFSET)
                usedOutput[i-OUTPUT_OFFSET] = true;
            else if (i >= INPUT_OFFSET)
                usedInput[i-INPUT_OFFSET] = true;
            else if (j >= OUTPUT_OFFSET)
                usedOutput[j-OUTPUT_OFFSET] = true;
            else if (j >= INPUT_OFFSET)
                usedInput[j-INPUT_OFFSET] = true;
        }
        else if ((led = dynamic_cast<LED *>(*it)))
        {
            if (led->col >= 0 && led->col < 10)
                outLedList[led->col] = led;
            else
                ledList.push_back(led);
            led->switchOn(POWER);
        }
        else if ((ic = dynamic_cast<IC *>(*it)))
        {
            icList.push_back(ic);
        }
    }

    for (size_t i = 0; i < IO_COUNT; i++)
    {
        terminals.setstate(OUTPUT_OFFSET + i, State::undefined);
    }
    silentOutput = false;
#ifdef QT_DEBUG
    //terminals.print();
#endif
}
Example #4
0
bool State::LEDWhiteDim()
{
	bool State=led.WhiteDim();
	if (State==0)
		return 0;
	else
	{
		while(led.WhiteDim());
		return 1;
	}
}
Example #5
0
////////////////////////
///两个灯一起闪烁n次
///@param 另一个灯的引用
///@param time 闪烁次数
///@param Interval 闪烁间隔(ms)
///////////////////////
void LED::Blink2(LED &led,uint8_t time,uint16_t interval)
{
	for(uint8_t i=0;i<time;++i)
	{
		On();
		led.On();
		TaskManager::DelayMs(interval);
		Off();
		led.Off();
		TaskManager::DelayMs(interval);
	}
}
Example #6
0
int main(void)
{
	SystemInit();
	TickTimer::Init();
	led.Init();
    while(1)
    {
    	led.On(led_all);
    	TickTimer::DelayMs(100);
    	led.Off(led_all);
    	TickTimer::DelayMs(200);
    }
}
Example #7
0
/*Main Function*/
int main(void) {

	red_led.clear_led();
	blue_led.set_led();

	/*Configure SysTick to tick at every 200msec*/
	SysTick_Config(4800000);

	while(1)
	{
		/*Do nothing*/
	}
    return 0 ;
}
Example #8
0
int launchChildProcess(int processIndex, ChildProcess *childProcesses, int totalChildProcesses, LED &ledIndicator) {

    int status, waitTimeout = 0;
    pid_t childID, endID;
    time_t when;

    if ((childID = fork()) == -1) { // Start child process.
        perror("fork error");
        exit(EXIT_FAILURE);
    }
    else if (childID == 0) {    // The child process.
        exit(childProcesses[processIndex].func());
    }
    else // The parent process.
    {
        char *descr = childProcesses[processIndex].description;
        time(&when);
        printf("Parent process started at %s", ctime(&when));

        for(;;) { // Wait for child process to terminate.
            endID = waitpid(childID, &status, WNOHANG|WUNTRACED);

            if (endID == -1) // Error calling waitpid.
            {
                perror("waitpid error");
                exit(EXIT_FAILURE);
            }
            else if (endID == 0) // Child still running.
            {
                time(&when);
                printf("Waiting for %s at %s", descr, ctime(&when));
                waitTimeout++ % 2 == 0 ? ledIndicator.on() : ledIndicator.off();
                sleep(1);
            }
            else if (endID == childID) // Child ended.
            {
                if (WIFEXITED(status))
                    printf("%s ended normally. status: %d at %s\n", descr, status, ctime(&when));
                else if (WIFSIGNALED(status))
                    printf("%s ended because of an uncaught signal at %s.\n", descr, ctime(&when));
                else if (WIFSTOPPED(status))
                    printf("%s process has stopped at %s.\n", descr, ctime(&when));
                return status;
            }
        }
    }
    return 1;
}
/**
*  @brief
*    Called when a control of the input controller has been activated
*/
void Application30::OnControl(Control &cControl)
{
	// Get name of control
	String sControl = cControl.GetName();

	// Display control value
	String sValue;
	if (cControl.GetType() == ControlButton)
		sValue = static_cast<Button&>(cControl).IsPressed() ? "<pressed>" : "<released>";
	else if (cControl.GetType() == ControlAxis)
		sValue = String::Format("%5.2f", static_cast<Axis&>(cControl).GetValue());
	System::GetInstance()->GetConsole().Print("- '" + sControl + "': " + sValue + '\n');

	// LED test
	if ((cControl.GetName() == "Plus" || cControl.GetName() == "Minus") && static_cast<Button&>(cControl).IsPressed()) {
		// Get LED control
		LED *pLED = static_cast<LED*>(cControl.GetController()->GetControl("LED"));
		if (pLED) {
			// Change LED value
			uint32 nLED = pLED->GetLEDs();
			if (cControl.GetName() == "Plus")
				nLED++;
			else
				nLED--;
			if (nLED > 15)
				nLED = 0;
			pLED->SetLEDs(nLED);
		}
	}

	// Rumble test
	if (cControl.GetName() == "Button1" || cControl.GetName() == "Button2") {
		// Get rumble control (try "Rumble3" first for joystick, then "Rumble1" for WiiMote)
		Effect *pRumble = static_cast<Effect*>(cControl.GetController()->GetControl("Rumble3"));
		if (!pRumble)
			pRumble = static_cast<Effect*>(cControl.GetController()->GetControl("Rumble1"));
		if (pRumble) {
			// Enable or disable rumble?
			if (cControl.GetName() == "Button1")
				pRumble->SetValue(1.0f);
			if (cControl.GetName() == "Button2")
				pRumble->SetValue(0.0f);
		}
	}
}
Example #10
0
bool one2two() {
    bool pressed = button_pressed();
    if (pressed) {
        lcd.display();
        led.on();
        lcd.print("Counting!");
    }
    return pressed;
}
/******************************************************************************
 * @author Julian Brackins
 *
 * @par Description:
 * Convert integers to strings lmaoooo.
 *
 * @param[in] light - an led light being tracked
 * @param[in] frame - image matrix
 * 
 * @returns Set of coordinates in the Coord class structure, giving you (x,y)
 *
 *****************************************************************************/
Coord drawObject(LED light, Mat &frame)
{
  //Draw a circle around the object being tracked

  cv::circle( frame, cv::Point( light.getX(),light.getY() ), 10, cv::Scalar(0,0,255));
  cv::putText(frame, intToString( light.getX() ) + " , " + intToString( light.getY() ), 
  cv::Point(light.getX(), light.getY() + 20 ), 1, 1, cv::Scalar(0,255,0));
  Coord point;
  point.setX(light.getX());
  point.setY(light.getY());
  return point;
}
Example #12
0
void setup() {
	Serial.begin(9600);
    lcd.begin(16, 2);
    led.on();
	machine.add_transition(0, 1, &button_pressed);
	machine.add_transition(1, 2, &one2two);
	machine.add_transition(2, 0, &button_pressed);
    machine.add_state_function(0, &hello);
    machine.add_state_function(1, &off);
    machine.add_state_function(2, &counting);
}
 void SetPins(int pinGreenLED, int pinOrangeLED, int pinRedLED, int pinFilterTurnLED, int pinPedLED, int pinBuzzer) {
     ledGreen.SetPin(pinGreenLED);
     ledGreen.SwitchOff();
     
     ledOrange.SetPin(pinOrangeLED);
     ledOrange.SwitchOff();
     
     ledRed.SetPin(pinRedLED);
     ledRed.SwitchOff();
     
     ledFilterTurn.SetPin(pinFilterTurnLED);
     ledFilterTurn.SwitchOff();
     
     ledPed.SetPin(pinPedLED);
     ledPed.SwitchOff();
     
     crossingBuzzer.SetPin(pinBuzzer);
     crossingBuzzer.SetFrequency(BUZZER_FREQ);
     crossingBuzzer.TurnOffAlarm();
 }
Example #14
0
void setup()
{
	ebox_init();

	PPS_PIN.mode(OUTPUT_PP);
	pps_off();
	uart1.begin(115200);
	led.begin();
	btn.begin();
	date_time.begin(115200);

}
Example #15
0
void setup()
{
    attachInterrupt(0,calcInput0,CHANGE);
    attachInterrupt(1,calcInput1,CHANGE);
    Serial.begin(9600);
    L5.init();
    L6.init();
    L7.init();
    L8.init();
    L9.init();
    L10.init();
    
}
 // this function simulates normal light condition when called at every loop
 // it automatically transitions from green to red signal by using the OrangeTransitionCounter
 void UpdateWithLightTransition(bool goSignal, bool turnLight, bool pedLight, int orangeLightTime) {
 
     // if green or go signal turn off transitioning process 
     // and only light up the green light
     if (goSignal) {
         transitionState = 0;
         GreenLight();
     }
     
     // if red signal and green light was previously on
     // start transitioning to red by firt turning on the 
     // orange light
     else if(!goSignal && ledGreen.IsOn() && transitionState == 0) {
         OrangeLight();
         transitionState = 1;
         OrangeTransitionCounter.Reset();
     } 
     // if red signal and greenlight was not on, directly
     // switch on the red light
     else if(!goSignal && !ledGreen.IsOn() && transitionState == 0)
         RedLight();
     
     // check if we are still transitioning to red light
     // if orangeTransitionCounter has passed orangeLightTime interval 
     // turn on the Red light only
     if (transitionState == 1) {
         if (OrangeTransitionCounter.GetCounter() < orangeLightTime)
             OrangeLight();
         else
             transitionState = 2;
     }
     
     if (transitionState == 2)
         RedLight();
         
     if (turnLight)
         ledFilterTurn.SwitchOn();
     else
         ledFilterTurn.SwitchOff();
     
     // ped lights turn on only when the normal lights are in red signal
     if (pedLight && ledRed.IsOn())
         ledPed.SwitchOn();
     else
         ledPed.SwitchOff();
 }
Example #17
0
int main(void)
{
	setup();
	while(1)
	{
		

		if(date_time.process() == 1)
		{
			clock.set_date_time(date_time.date_time);
			memcpy(buf,date_time.date_time,14);
			buf[12] = clock.dt.week;
			led.show_date_time(buf);
			current_systick = millis();
		}
		
		if(millis() - current_systick > 500)
			pps_off();
		else
			pps_on();
	}


}
 // this function lights the orange light only switching off
 // the turn and the ped light as well
 void RoadWorkLightOnly(){
     OrangeLight();
     ledPed.SwitchOff();
     ledFilterTurn.SwitchOff();
 }
Example #19
0
bool State::LEDGold()
{
	return led.GoldState();
}
Example #20
0
void loop()
{
    if(bNewThrottleSignal0&&bNewThrottleSignal1&&
       1)
    {
        int A= nThrottleIn0;
        Serial.print("0:");
        Serial.print(A);
        Serial.print(" 1:");
        int B= nThrottleIn1;
        Serial.println(B);
        
        
        if(A<1910){
            
            //forward
            if(A<1400 && B>1400 && B<1600){
                P5.writeForward(A);
                P6.writeForward(A);
                P7.writeForward(A);
                P8.writeForward(A);
                
                //  L5.on();
                //  L8.on();
                //  L7.on();
                //  L6.on();
                
                L9.off();
                L10.off();
            }
            //Left
            else if(B<1400){
                P6.writeForward(1300);
                P8.writeForward(1300);
                P5.writeBackward(1700);
                P7.writeBackward(1700);

                L9.on();
                L10.off();
            }

            else if(B>1600){
                P5.writeForward(1300);
                P7.writeForward(1300);
                P6.writeBackward(1700);
                P8.writeBackward(1700);

                L10.on();
                L9.off();
            }

            //turn left
            // else if(B<1400 && A<1400){
            //     int sa = ((A-1400)*(-1))+1600;
            //     P6.writeForward(A);
            //     P8.writeForward(A);
            //     P5.writeBackward(sa);
            //     P7.writeBackward(sa);
                
            //     //  L5.off();
            //     //  L6.on();
            //     //  L7.off();
            //     //  L8.on();
                
            //     L9.on();
            //     L10.off();
            // }
            // //turn right
            // else if(B>1600 && A<1400){
            //     int sa = ((A-1400)*(-1))+1600;
            //     P5.writeForward(A);
            //     P7.writeForward(A);
            //     P6.writeBackward(sa);
            //     P8.writeBackward(sa);
                
            //     //  L5.on();
            //     //  L6.off();
            //     //  L7.on();
            //     //  L8.off();
                
            //     L9.off();
            //     L10.on();
            // }
            //backward
            else if(A>1600 && B>1400 && B<1600){
                P5.writeBackward(A);
                P6.writeBackward(A);
                P7.writeBackward(A);
                P8.writeBackward(A);
                
                //  L5.on();
                //  L6.on();
                //  L7.on();
                //  L8.on();
                
                L9.on();
                L10.on();
            }
            //leftback
            // else if(B<1400 && A>1600){
            //     int sa = 1400 - (A-1600);
            //     P6.writeBackward(A);
            //     P8.writeBackward(A);
            //     P5.writeForward(sa);
            //     P7.writeForward(sa);
                
            //     //  L5.off();
            //     //  L6.on();
            //     //  L7.off();
            //     //  L8.on();
                
            //     L9.off();
            //     L10.on();
            // }
            // //rightback
            // else if(B>1600 && A>1600){
            //     int sa = 1400 - (A-1600);
            //     P5.writeBackward(A);
            //     P7.writeBackward(A);
            //     P6.writeForward(sa);
            //     P8.writeForward(sa);
            //     //  L5.on();
            //     //  L6.off();
            //     //  L7.on();
            //     //  L8.off();
                
            //     L9.on();
            //     L10.off();
            // }
            else{
                L5.off();
                L6.off();
                L7.off();
                L8.off();
                
                L9.off();
                L10.off();
            }
        }

        else if(A>1910){
            L5.off();
            L6.off();
            L7.off();
            L8.off();
            
            L9.off();
            L10.off();
        }
        
        bNewThrottleSignal0 = false;
        bNewThrottleSignal1 = false;
    }
}
/******************************************************************************
 * @author Julian Brackins
 *
 * @par Description:
 * After the images have been filtered properly, this function
 * handles determining if an image contains a blob that fits in the HSV range
 * of the colour being tracked.
 *
 * @param[in] light - an led light being tracked
 * @param[in] threshold - thresholded image matrix
 * @param[in] HSV - Matrix containing HSV values
 * @param[in] cameraFeed - Matrix containing camera feed
 * 
 * @returns Set of coordinates in the Coord class structure, giving you (x,y)
 *
 *****************************************************************************/
Coord trackFilteredObject(LED lights,Mat threshold,Mat HSV, Mat &cameraFeed)
{
  //Maybe change all this so that It doesn't refer to everything as lights...
  LED blob;

  Coord coordinates;

  Mat tempMatrix;
  threshold.copyTo(tempMatrix);

  //findContours params
  vector<vector<Point>> contours;
  vector<Vec4i> hierarchy;

  //find the contours of the image using openCV
  findContours( tempMatrix, contours, hierarchy,CV_RETR_CCOMP,CV_CHAIN_APPROX_SIMPLE );

  //use moments method to find our filtered object
  double refArea = 0;
  bool objectFound = false;

  //Zero out the coordinates
  coordinates.setX(0);
  coordinates.setY(0);

  if (hierarchy.size() > 0) 
  {
    int numObjects = hierarchy.size();
    //The filter becomes too noisy if the numObjects is too great...
    if(numObjects < MAX_OBJS)
    {
      for (int i = 0; i >= 0; i = hierarchy[i][0]) 
      {
        Moments moment = moments((cv::Mat)contours[i]);
        double area = moment.m00;

        //if the area is less than 20 px by 20px then it is probably just noise
        //if the area is the same as the 3/2 of the image size, probably just a bad filter
        //we only want the object with the largest area so we safe a reference area each
        //iteration and compare it to the area in the next iteration.
        if(area>MIN_OBJ_AREA)
        {
          blob.setX(moment.m10/area);
          blob.setY(moment.m01/area);
          blob.setColour(lights.getColour());
          blob.setText(lights.getText());

          //Push onto vector if allowing multiples of one colour
          //blobvec.push_back(blob);
          objectFound = true;
        }
        else 
          objectFound = false;
      }
      
      //let user know you found an object
      if(objectFound ==true)
      {
        //draw object location on screen
        //use vector version of drawObject if allowing multiples
        coordinates = drawObject(blob,cameraFeed);
        coordinates.setTracking(true);
      }
      else
      {
        coordinates.setTracking(false);
      }
    }
    else putText(cameraFeed,"Adjust Filter, too much noise.",Point(0,50),1,2,Scalar(0,0,255),2);
  }
  return coordinates;
}
Example #22
0
// Lower drill, outputs 2sec pulse to lowering pin
void LowerDrill(){
  DrillDown.on();
  timer.setTimeout(2000, StopDrillMove);
}
Example #23
0
// Stop drill movement, sets lifting and lowering pins to LOW state.
void StopDrillMove(){
  DrillUp.off();
  DrillDown.off();
}
Example #24
0
void State::LEDWhiteOff()
{
	led.WhiteOff();
}
Example #25
0
// Lift drill, outputs 2sec pulse to lifting pin.
void LiftDrill(){
  DrillUp.on();
  timer.setTimeout(2000, StopDrillMove);
}
Example #26
0
bool State::LEDWhite()
{
	return led.WhiteState();
}
Example #27
0
void off() {
    lcd.noDisplay();
    led.off();
}
Example #28
0
void State::LEDGoldOn()
{
	led.GoldOn();
}
Example #29
0
void State::LEDGoldOff()
{
	led.GoldOff();
}
Example #30
0
void State::LEDWhiteOn()
{
	led.WhiteOn();
}