Trinket 5v programming Please Help !

Hello, I’m trying to use constant for better performance and the the sketch to detect pulse on pin 3 and pulse the pin 4 at a certain rate detect pulse on pin 2 and pulse pin 1 at a certain rate pin 0 will be used to light up A green 3.0v led. The on time for the speaker or buzzer should be 30 seconds or less.

I have been trying to get help with this without returning the chips to the store as defective

sketch_apr11_repeater.ino (3.94 KB)

Your code, posted properly. Please use code tags.

/* Trinket/Gemma compatible IR read sketch
This sketch/program uses an Adafruit Trinket or Gemma
ATTiny85 based mini microcontroller and a PNA4602 or TSOP38238 to
read an IR code and perform a function.  In this
test program, tones are generated to a piezo speaker
but you can use codes to trigger any function you wish.
Based on Adafruit tutorial http://learn.adafruit.com/ir-sensor/using-an-ir-sensor
and http://learn.adafruit.com/trinket-gemma-mini-theramin-music-maker
*/
 
// We need to use the 'raw' pin reading methods because timing is very important here 
// and the digitalRead() procedure is slower!
#define IRpin_PIN  PINB // ATTiny85 had Port B pins
#define ledpin     4    // Piezo speaker on Trinket/Gemma Pin GPIO #4/D4
#define IRpin      3    // IR sensor - TSOP38238 on Pin GPIO #3 / D3
#define IRpin      2    // IR sensor - TSOP38238 on Pin GPIO #2 / D2
#define SPEAKERPIN 1    // Piezo speaker on Trinket/Gemma Pin GPIO #1/D1
#define button     0    // button - Trinket/Gemma Pin GPIO #0/D0
 
#define MAXPULSE    5000  // the maximum pulse we'll listen for - 5 milliseconds 
#define NUMPULSES    100  // max IR pulse pairs to sample
#define RESOLUTION     2  // // time between IR measurements
 
// we will store up to 100 pulse pairs (this is -a lot-, reduce if needed)
uint16_t pulses[100][2];   // pair is high and low pulse
uint16_t currentpulse = 0; // index for pulses we're storing
uint32_t irCode = 0;
 
void setup() {
  pinMode(ledpin, OUTPUT); // Output tones on Trinket/Gemma pin D4
  pinMode(IRpin, INPUT);       // Listen to IR receiver on Trinket/Gemma pin D3
  pinMode(IRpin, INPUT);       // Listen to IR receiver on Trinket/Gemma pin D2
  pinMode(SPEAKERPIN, OUTPUT); // Output tones on Trinket/Gemma pin D1
  pinMode (button , INPUT);  // Input button on Trinket/Gemma pin D0
}
 
void loop() {
  
  irCode=listenForIR(); // Wait for an IR Code
 
  // Process the pulses to get our code
  for (int i = 0; i < 32; i++) {
    irCode=irCode<<1;
    if((pulses[i][0] * RESOLUTION)>0&&(pulses[i][0] * RESOLUTION)<500) {
      irCode|=0; 
    } else {
      irCode|=1;
    }
  }
  if(irCode==1000,600)  {      // "1" on my remote, USE YOUR CODE HERE
    beep(SPEAKERPIN,); }  // Make a 400 Hz beep
  else if (irCode==) { // "2", USE YOUR OWN HEX CODE HERE
    beep(SPEAKERPIN); }  // Make a 500 Hz beep
  else if (irCode==) { // "3", USE YOUR OWN HEX CODE HERE
    beep(SPEAKERPIN); } // Make a 600 Hz beep
  else if (irCode==) { // "4", USE YOUR OWN HEX CODE HERE
         (SPEAKERPIN,75950,9000);  // Make a 700 Hz beep
         
  }
  
} // end loop
 
 
uint16_t listenForIR() {  // IR receive code
  currentpulse = 0;
  while (1) {
   unsigned int highpulse, lowpulse;  // temporary storage timing
   highpulse = lowpulse = 0; // start out with no pulse length 
  
   while (IRpin_PIN & _BV(IRpin)) { // got a high pulse
      highpulse++; 
      delayMicroseconds(RESOLUTION);
      if (((highpulse >= MAXPULSE) && (currentpulse != 0))|| currentpulse == NUMPULSES) {
        return currentpulse; 
      }
   }
   pulses[currentpulse][0] = highpulse;
 
   while (! (IRpin_PIN & _BV(IRpin))) { // got a low pulse
      lowpulse++; 
      delayMicroseconds(RESOLUTION);
      if (((lowpulse >= MAXPULSE) && (currentpulse != 0))|| currentpulse == NUMPULSES) {
        return currentpulse; 
      }
   }
   pulses[currentpulse][1] = lowpulse;
   currentpulse++;
  }
}
 
// Generate a tone on speakerPin - Trinket/Gemma/ATTiny85 compatible
void beep (unsigned char speakerPin, int frequencyInHertz, long timeInMilliseconds)
{   // http://web.media.mit.edu/~leah/LilyPad/07_sound_code.html
          int x;   
          long delayAmount = (long)(1000000/frequencyInHertz);
          long loopTime = (long)((timeInMilliseconds*1000)/(delayAmount*2));
          for (x=0;x<loopTime;x++)   
          {  
              digitalWrite(speakerPin,HIGH);
              delayMicroseconds(delayAmount);
              digitalWrite(speakerPin,LOW);
              delayMicroseconds(delayAmount);
          }  
}

Please explain what the program should do, and what it does instead.

See the “How to use this forum” post for more information.