Example #1
0
// Public: Play entire song and wait till song finishes
void WtvPadawan::playVoice(unsigned int voiceNumber){
  sendCommand(voiceNumber);
  // Wait 20ms for busy to be active
  delayMicros(20000);
  // Wait till song ends
  _busyPinState=digitalRead(_busyPin);
  while(_busyPinState==HIGH){
    _busyPinState=digitalRead(_busyPin);
  }
}
Example #2
0
// Private: Send command to sound module
void WtvPadawan::sendCommand(unsigned int command) {
  
  //Start bit Low level pulse.
  digitalWrite(_clockPin, LOW);
  // Initialize timer
  delayMicros(0);
  // Wait Start bit length minus 50 us
  delayMicros(1950);
  for (unsigned int mask = 0x8000; mask > 0; mask >>= 1) {
    //Clock low level pulse.
    digitalWrite(_clockPin, LOW);
    delayMicros(50);
    //Write data setup.
    if (command & mask) {
      digitalWrite(_dataPin, HIGH);
    } else {
      digitalWrite(_dataPin, LOW);
    }
    //Write data hold.
    delayMicros(50);
    //Clock high level pulse.
    digitalWrite(_clockPin, HIGH);
    delayMicros(100);
  }
  //Stop bit high level pulse (additional 1900us).
  delayMicros(1900);
}
Example #3
0
// TODO: return value converted to mm distance length
word dist_read(void) {
    PACNT = 0;  // Reset pulse accumulator count
    PAFLG = PAFLG_PAIF_MASK;    // Clear interrupt edge flag by writing a one to it
    
    // Generate 10us trigger pulse
    TRIG_PIN = 1;
    delayMicros(10);
    TRIG_PIN = 0;
    
    while(!PAFLG_PAIF); // Wait for falling edge on echo pin
    
    // Check in case of PACNT overflow
    if(PAFLG_PAOVF) {
        PAFLG = PAFLG_PAOVF_MASK;   // Clear overflow flag by writing a one to it
        return 0;
    }
    
    return PACNT;
}
Example #4
0
WtvPadawan::WtvPadawan(int clockPin,int dataPin,int busyPin)
{
  // Save private values from constructor
  _clockPin=clockPin;
  _dataPin=dataPin;
  _busyPin=busyPin;
  
  // Set initial values
  _busyPinState=HIGH;
  _currentVolume = VOLUME_MAX;

  // Initialize timer
  _lastMicros = 0;
  delayMicros(0);

  // Set pins
  
  pinMode(_clockPin, OUTPUT);
  pinMode(_dataPin, OUTPUT);
  pinMode(_busyPin, INPUT);

}
Example #5
0
Wtv::Wtv(int clockPin,int dataPin)
{
  // Save private values from constructor
 
  _clockPin=clockPin;
  _dataPin=dataPin;
  
  
  // Set initial values
  
  _currentVolume = VOLUME_MAX;

  // Initialize timer
  _lastMicros = 0;
  delayMicros(0);

  // Set pins
  
  pinMode(_clockPin, OUTPUT);
  pinMode(_dataPin, OUTPUT);
 

}
Example #6
0
// delay for given milli seconds
void delay(unsigned long t) {
    delayMicros(t * 1000);
}