コード例 #1
0
ファイル: matrix.cpp プロジェクト: tmitchell/oosmos
static bool Running_State_Code(void * pObject, oosmos_sRegion * pRegion, const oosmos_sEvent * pEvent)
{
  matrix * pMatrix = (matrix *) pObject;

  switch (pEvent->Code) {
    case oosmos_INSTATE:
      oosmos_SyncBegin(pRegion);
        while (true) {
          for (pMatrix->m_CurrentRowIndex = 0; pMatrix->m_CurrentRowIndex < pMatrix->m_Rows; pMatrix->m_CurrentRowIndex++) {
            if (pMatrix->m_pRowPins[pMatrix->m_CurrentRowIndex] == NULL)
              continue;

            pinOn(pMatrix->m_pRowPins[pMatrix->m_CurrentRowIndex]);
            oosmos_SyncDelayMS(pRegion, RowOnSettleTimeUS);

            InterrogateColumns(pMatrix);

            pinOff(pMatrix->m_pRowPins[pMatrix->m_CurrentRowIndex]);
            oosmos_SyncDelayMS(pRegion, RowOffSettleTimeUS);
          }
        }
      oosmos_SyncEnd(pRegion);
      return true;
  }

  return false;
}
コード例 #2
0
ファイル: stepper.c プロジェクト: YTakami/makecontroller
/**
	Enable a stepper motor.
	@param stepper Which stepper (0 or 1).
	
	\b Example
	\code
	// enable stepper 1
	stepperEnable(1);
	\endcode
*/
void stepperEnable(int stepper)
{
  fasttimerInit(2);
  Stepper* s = &steppers[stepper];
  pwmEnableChannel(stepper * 2);
  pwmEnableChannel(stepper * 2 + 1);
  // Fire the PWM's up
  s->duty = 1023;

  int pwm = stepper * 2;
  pwmSetDuty(pwm, s->duty);
  pwmSetDuty(pwm + 1, s->duty);

  // Get IO's
  int i;
  for (i = 0; i < 4; i++) {
    s->pins[i] = stepperGetIo(stepper, i);
    pinSetMode(s->pins[i], OUTPUT);
    pinOn(s->pins[i]);
  }

  s->position = 0;
  s->destination = 0;
  s->speed = STEPPER_DEFAULT_SPEED;
  s->timerRunning = 0;
  s->halfStep = false;
  s->bipolar = true;

  s->fastTimer.handler = stepperIRQCallback;
  s->fastTimer.id = stepper;
  fasttimerStart(&s->fastTimer, s->speed * 1000, true);
}
コード例 #3
0
ファイル: lightorgan.cpp プロジェクト: JPry/musical-pi
void allOn()
{
    int i;
    for (i = 0; i < TOTAL_PINS; i++) {
        pinOn(i);
    }
}
コード例 #4
0
ファイル: lcd.cpp プロジェクト: tmitchell/oosmos
static void Write4(lcd * pLCD, const uint8_t Value) 
{ 
  (Value & 1 ? pinOn : pinOff)(pLCD->m_pData4);
  (Value & 2 ? pinOn : pinOff)(pLCD->m_pData5);
  (Value & 4 ? pinOn : pinOff)(pLCD->m_pData6);
  (Value & 8 ? pinOn : pinOff)(pLCD->m_pData7);

  pinOn(pLCD->m_pE);
  oosmos_DelayUS(1);
  pinOff(pLCD->m_pE);
}
コード例 #5
0
ファイル: lcd.cpp プロジェクト: tmitchell/oosmos
static void SetMode(lcd * pLCD, const eMode Mode)
{
  switch (Mode) {
    case modeWriteCommand:
      pinOff(pLCD->m_pRS);     
      if (pLCD->m_pRW != NULL) pinOff(pLCD->m_pRW);
      break;
    case modeWriteData:
      pinOn(pLCD->m_pRS);    
      if (pLCD->m_pRW != NULL) pinOff(pLCD->m_pRW);
      break;
    case modeReadStatus:
      pinOff(pLCD->m_pRS);     
      if (pLCD->m_pRW != NULL) pinOn(pLCD->m_pRW);
      break;
    case modeReadData:
      pinOn(pLCD->m_pRS);   
      if (pLCD->m_pRW != NULL) pinOn(pLCD->m_pRW);
      break;
  }
}
コード例 #6
0
ファイル: main.cpp プロジェクト: RCXD/msp430
int main (void)
{
  // Set up the switch and callback function
  int_sw sw = int_sw(SW_PIN, &toggleLED);
  // Configure the LED_PIN as an output
  pinOutput(LED_PIN);
  pinOn(LED_PIN);
  // Already done by clock library, but enable interrupts again anyway
  _EINT();
  // Enter low power mode 3
  LPM3;
}
コード例 #7
0
// beep for a quarter of a second
void beep(void) {
  outputs(pin(0) | pin(1));
  pinOff(1);
  
  byte i = 0;
  while (i < 250) {
    delay(1);
    pinOn(pin(0));
    delay(1);
    pinOff(pin(0));
    i++;
  }
}
コード例 #8
0
int main() {
  // Setup the comparator
  becomeInput(0);
  becomeInput(1);
  pinOff(0);
  pinOff(1);
  
  // Setup our outputs
  becomeOutput(2);
  becomeOutput(3);
  becomeOutput(4);
  // Not using this, it's the reset pin!
  //becomeOutput(5);
  
  // Todo: See if the internal bandgap is a good enough voltage for comparator
  
  // Magic analog comparator configuration voodoo:
  // ACD=0, ACBG=0, ACO=0 ACI=0 ACIE=0 ACIC=0 ACIS1, ACIS0
  // - interrupt on output toggle
  ACSR = 0b00000000;
  // ADEN=1
  ADCSRA = 0b10000000;
  // ACME=0 (on) ADEN=0 MUX = b000 for use of AIN1
  ADCSRB = 0b00000000;
  // Save some power by turning off the digital input on AIN0 and AIN1
  DIDR0 = 0b00111100;
  // Voodoo done.
  
  // Do a little dance!
  unsigned char output = first_output;
  unsigned long gap = 0;
  while(true) {
    //gap = pollComparatorUntil(false); // wait till the thingy goes low (i.e. pulse done!)
    gap = pollComparatorUntil(true); // wait till it does high, and then...
    
    if (output <= max_output) pinOff(output); // turn off the last servo
    output++; // change to the next one
    
    if (gap > reset_gap_minimum) {
      output = first_output;
    }
    
    // Pop the new Servo's signal on!
    if (output <= max_output) pinOn(output); 
  }
  
  return 0;
}
コード例 #9
0
ファイル: Servo.c プロジェクト: NeuronRobotics/ServoStock
void servoTimerEvent()
{
        //mPORTDToggleBits(BIT_3);
	//StartCritical();
        stopServos();
        int j;
        switch(servoStateMachineCurrentState){
            case LOW:
                updateAllEncoders();
                if(getRunPidIsr()){
                    RunPIDControl();
                    //Print_Level l = getPrintLevel();
                    interpolateZXY();
                    //setPrintLevelNoPrint();
                    
                }
                //runLinearInterpolationServo(start,stop);
                runSort();
                for (j=0;j<NUM_SERVO;j++){
                    pinOn(j);
                }
                lastValue = 0;
                sortedIndex=0;
                //1ms delay for all servos
                setTimerPreTime();
                return;
            case PRETIME:
                if(setUpNextServo())
                    return;
            case TIME:
                stopCurrentServo();
                if(servoStateMachineCurrentState == TIME){
                    if(setUpNextServo() == false) {
                        //fast stop for channels with the same value
                        servoTimerEvent();
                    }
                }
                //If there are still more channels to be turned off after the recoursion, break
                if(servoStateMachineCurrentState != FINISH)
                    return;

            case FINISH:
                setTimerLowTime();
                return;
        }
        //EndCritical();
}
コード例 #10
0
ファイル: lightorgan.cpp プロジェクト: JPry/musical-pi
void midi_process(snd_seq_event_t *ev)
{

    // If this event is a PGMCHANGE type, it's a request to map a channel to an instrument
    if (ev->type == SND_SEQ_EVENT_PGMCHANGE) {
        //printf("PGMCHANGE: channel %2d, %5d, %5d\n", ev->data.control.channel, ev->data.control.param,  ev->data.control.value);

        // Clear pins state, this is probably the beginning of a new song
        allOff();
    }

    // If the event is SND_SEQ_EVENT_BOUNCE, then maybe this is an interrupt?
    if (ev->type == SND_SEQ_EVENT_BOUNCE) {
        allOff();
    }

    if (channelActive == ev->data.control.channel) {
        // Note on/off event
        if (ev->type == SND_SEQ_EVENT_NOTEON) {

            // When pinActive is -1, we're playing the first note
            if (-1 == pinActive) {
                pinActive = 0;
            } else {
                // First turn off the current pin
                printf("Turning off pin %d\n", pinActive);
                pinOff(pinActive);

                // Increment pinActive
                printf("Incrementing pinActive\n");
                pinActive++;

                // Reset to zero if we're above the number of pins
                if (pinActive >= TOTAL_PINS) {
                    printf("Resetting pinActive to zero\n");
                    pinActive = 0;
                }
            }

            // Turn on the next pin
            printf("Turning on pin %d\n", pinActive);
            pinOn(pinActive);
        }
    }

    snd_seq_free_event(ev);
}
コード例 #11
0
ファイル: main.cpp プロジェクト: RCXD/msp430
int main(void)
{
  basic_clock clock = basic_clock();
  spi spi_test = spi(SPI_B0);

  pinOutput(LED_PIN);
  pinOutput(LED_PIN2);
  pinOn(LED_PIN2);

  for (;;) //ever
  {
    for (uint8_t i=0; i<255; i++)
    {
      spi_test.write(i);
    }
    pinToggle(LED_PIN);
    pinToggle(LED_PIN2);
    _delay_s(1);
  }
}
コード例 #12
0
ファイル: main.cpp プロジェクト: RCXD/msp430
int main(void)
{
  basic_clock clock = basic_clock(DCO_F_1MHz);
  tlc5925 tlc = tlc5925(p1_4);

  pinOutput(LED_PIN);
  pinOutput(LED_PIN2);
  pinOn(LED_PIN2);

  tlc.write((uint16_t)TLC5925_CH01);
  _delay_s(2);
  tlc.write((uint16_t)TLC5925_CH0_15);
  _delay_s(5);

  for (;;) //ever
  {
    tlc.shiftDown(16,TLC5925_CH00);
    pinToggle(LED_PIN);
    pinToggle(LED_PIN2);
    _delay_s(1);
  }
}
コード例 #13
0
ファイル: InterruptServo.c プロジェクト: NeuronRobotics/dyio
void servoTimerEvent()
{
	//int flag = FlagBusy_IO;
	if(blockIndex>=dataTableSize){
		println_E("Bad block size");
		return;
	}
	switch(servoStateMachineCurrentState){
		case STARTLOOP:
			FlagBusy_IO=1;
			pinOn( blockIndex );
			servoStateMachineCurrentState = BON;
			OCR1A = blockData[blockIndex].toBON;

			break;

		case BON:
			pinOn( blockIndex + 12 );
			servoStateMachineCurrentState =AOFF;
			OCR1A = blockData[blockIndex].toAOFF;

			break;
		case AOFF:
			pinOff(blockIndex );
			servoStateMachineCurrentState = FINISH;
			OCR1A = blockData[blockIndex].toFINISH;

			break;
		case FINISH:
			pinOff(blockIndex + 12 );
			//UART is now clear to send while timers are re-calculated and the server is run
			FlagBusy_IO=0;
			EndCritical();

			TCCR1Bbits._CS=0;// stop the clock
			//If block is now done, reset the block index and sort
			blockIndex++;
			if(blockIndex == dataTableSize){
				// this resets the block Index
				blockIndex=0;
			}
			updateTimer(TCNT1);
			TCNT1=0;// Start from zero for each pulse section
			currentTimer = 0;

			updateServoValues();
			servoStateMachineCurrentState = STARTLOOP;
			blockData[blockIndex].toBON = 	calcTimer (	LOOPSPACING+LOOPPERIOD - (	OFFSET+blockData[blockIndex].positionTempB)	);
			blockData[blockIndex].toAOFF=	calcTimer (	LOOPSPACING+				OFFSET+blockData[blockIndex].positionTempA	);
			blockData[blockIndex].toFINISH=	calcTimer (	LOOPSPACING+LOOPPERIOD );

			setServoTimer( LOOPSPACING);

			TCCR1Bbits._CS = 2;//  value CLslk I/O/8 (From prescaler)

			break;
	}

	//FlagBusy_IO=flag;

}