Exemplo n.º 1
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++;
  }
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
void allOff()
{
    int i;
    for (i = 0; i < TOTAL_PINS; i++) {
        pinOff(i);
    }
}
Exemplo n.º 5
0
void stopCurrentServo(){
    pinOff(sort[sortedIndex]);
    sortedIndex++;
    if(sortedIndex == dataTableSize){
        servoStateMachineCurrentState = FINISH;
        //fall through to finish
    }
}
Exemplo n.º 6
0
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);
}
Exemplo n.º 7
0
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;
  }
}
Exemplo n.º 8
0
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);
}
Exemplo n.º 9
0
/**
  Disable a stepper motor.
  @param stepper Which stepper (0 or 1).
*/
void stepperDisable(int stepper)
{
  Stepper* s = &steppers[stepper];
  if (s->timerRunning) {
    chSysDisable();
    fasttimerStop(&s->fastTimer);
    chSysEnable();
  }

  int i;
  for (i = 0; i < 4; i++)
    pinOff(s->pins[i]);

  int pwm = stepper * 2;
  pwmDisableChannel(pwm);
  pwmDisableChannel(pwm + 1);
}
Exemplo n.º 10
0
/**
 * Start the servo hardware
 */
void initServos(){

    SERVO_HW_INIT();

    if(getPrintLevel() == NO_PRINT){
        CloseUART1();
    }
    int i;
    for(i=0;i<dataTableSize;i++){
        pinOff(i);
        setServo(i,128,0);
    }
//    runLinearInterpolationServo(start,stop);
//    runSort();
//    for(i=0;i<numPidMotor;i++){
//       println_I("Servo Positions: ");p_sl_I(getServoPosition(i));
//    }
//    for(i=0;i<numPidMotor;i++){
//       println_I("Sorted Servo Positions index: ");p_sl_I(sort[i]); print_I(" value: ");p_sl_I(position[sort[i]]);
//    }


    setTimerLowTime();
}
Exemplo n.º 11
0
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;

}