0

Trinket Pro 3V
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: Trinket Pro 3V

by sfoley on Wed Apr 20, 2016 5:55 pm

After reaching out to support to have this unit replaced, I never did hear back from them. I wound up buying an new trinket (same model) with some other parts I ordered, and it works just fine. At the moment, Im out $15, but I have a working trinket finally.

sfoley
 
Posts: 4
Joined: Tue Mar 22, 2016 8:13 pm

Re: Trinket Pro 3V

by franklin97355 on Wed Apr 20, 2016 6:33 pm

There are 15 replies to this thread. At what point were you ignored? Did you contact support@adafruit.com with a link to this thread and your order info? If you did please try again.

franklin97355
 
Posts: 21217
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Trinket Pro 3V

by sfoley on Wed Apr 20, 2016 10:38 pm

The forum help has been good, but it looks like my email to support@adafruit.com for a replacement slipped through the cracks the first go around. Got it all worked out this afternoon. Thanks for getting my project going again.

sfoley
 
Posts: 4
Joined: Tue Mar 22, 2016 8:13 pm

Re: Trinket Pro 3V

by HunterT on Wed Jun 28, 2017 11:36 am

Has a long term fix been found to this problem? I have three 3V ProTrinkets, and 2 are having this issue. I've used the same code in the past with no issue. I was successful uploading to one of the 3VProTrinkets, using the same computer (Mac 10.12.15), IDE (tried: 1.8.3*, 1.6.8, and 1.6.4), board library(tried: 1.4.5, 1.4.8, & 1.4.9*), code, cord... I can't get the code to upload to the other two.

I was successful uploading to 1 of 3 with 1.83 and 1.49 combo. The other two stay in bootload mode, with the pulsating red indefinitely. One of the non-working ones has a LiIon/LiPoly Backpack, the other two have not been touched with solder yet.

The error I get is:
Code: Select all | TOGGLE FULL SIZE
avrdude: error: usbtiny_send: Broken pipe (expected 128, got -32)

Code: Select all | TOGGLE FULL SIZE
avrdude: error: usbtiny_send: Operation timed out (expected 128, got -60)

Code: Select all | TOGGLE FULL SIZE
avrdude: error: usbtiny_receive: Broken pipe (expected 4, got -32)


Any help is appreciated.

HunterT
 
Posts: 9
Joined: Tue Jul 15, 2014 12:56 am

Re: Trinket Pro 3V

by agavenda on Sun Jul 30, 2017 11:15 pm

I'm getting identical errors to those that HunterT referenced. Any advice/help available?

Thanks!

agavenda
 
Posts: 2
Joined: Sun Jul 30, 2017 11:14 pm

Re: Trinket Pro 3V

by franklin97355 on Sun Jul 30, 2017 11:27 pm

What have you tried to fix it and are you running the same OS and version numbers? Are you getting the same error messages and on how many Trinkets have you tried this?

franklin97355
 
Posts: 21217
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Trinket Pro 3V

by agavenda on Sun Jul 30, 2017 11:41 pm

I've tried different USB ports and different USB cables using Mac 10.12.5, IDE 1.8.2, and Adafruit AVR Board 1.4.9.

Unfortunately I only had a need for one 3.3V/12MHz Trinket so that's the only one I've tested on.

I'm consistently getting the "Broken pipe (expected 128, got -32)" and "Content mismatch" errors.

I can sometimes get the Blink sketch to upload but its extremely intermittent and no other sketches will load.

Thanks!

agavenda
 
Posts: 2
Joined: Sun Jul 30, 2017 11:14 pm

Re: Trinket Pro 3V

by anthonybradley on Tue Aug 01, 2017 3:41 pm

sfoley wrote:I dropped back to IDE 1.6.5 and had to back up to Arduino AVR boards version 1.6.8 in the board manager to get it to compile (a.out problem with 1.6.10). It does compile with version 1.6.8 and Adafruit AVR Boards 1.4.6 in board manager. However, the (verbose) output is the same as before when I try to upload:
Code: Select all | TOGGLE FULL SIZE
avrdude: Version 6.0.1, compiled on Apr 14 2015 at 16:30:25
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/Users/sfoley/Library/Arduino15/packages/arduino/tools/avrdude/6.0.1-arduino5/etc/avrdude.conf"
         User configuration file is "/Users/sfoley/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : usb
         Using Programmer              : usbtiny
avrdude: usbdev_open(): Found USBtinyISP, bus:device: 020:024
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : USBtiny
         Description     : USBtiny simple USB programmer, http://www.ladyada.net/make/usbtinyisp/
avrdude: programmer operation not supported

avrdude: Using SCK period of 10 usec
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: Using SCK period of 10 usec
avrdude: reading input file "/var/folders/bs/g9p_b6h14w5_pv_j3ztyxcxw0000gn/T/build237949294981430414.tmp/Blink.cpp.hex"
avrdude: writing flash (1078 bytes):

Writing | #####
avrdude: error: usbtiny_send: Input/output error (expected 128, got -5)
######avrdude: 4 retries during SPI command
avrdude: 1 retries during SPI command
avrdude: 1 retries during SPI command
avrdude: 1 retries during SPI command
avrdude: 1 retries during SPI command
avrdude: 1 retries during SPI command
avrdude: 1 retries during SPI command
avrdude: 1 retries during SPI command
avrdude: 1 retries during SPI command
avrdude: 2 retries during SPI command
#avrdude: 1 retries during SPI command
###avrdude: 1 retries during SPI command
##avrdude: 1 retries during SPI command
###avrdude: 1 retries during SPI command
#avrdude: 1 retries during SPI command
#avrdude: 1 retries during SPI command
#avrdude: 1 retries during SPI command
#avrdude: 1 retries during SPI command
avrdude: 1 retries during SPI command
###avrdude: 1 retries during SPI command
avrdude: 1 retries during SPI command
########avrdude: 1 retries during SPI command
avrdude: 1 retries during SPI command
avrdude: 1 retries during SPI command
avrdude: 1 retries during SPI command
##avrdude: 1 retries during SPI command
##avrdude: 1 retries during SPI command
##avrdude: 1 retries during SPI command
avrdude: 1 retries during SPI command
#avrdude: 1 retries during SPI command
##avrdude: 1 retries during SPI command
avrdude: 1 retries during SPI command
avrdude: 1 retries during SPI command
avrdude: 1 retries during SPI command
#avrdude: 1 retries during SPI command
###avrdude: 1 retries during SPI command
## | 100% 7.44s

avrdude: 1078 bytes of flash written
avrdude: verifying flash memory against /var/folders/bs/g9p_b6h14w5_pv_j3ztyxcxw0000gn/T/build237949294981430414.tmp/Blink.cpp.hex:
avrdude: load data flash data from input file /var/folders/bs/g9p_b6h14w5_pv_j3ztyxcxw0000gn/T/build237949294981430414.tmp/Blink.cpp.hex:
avrdude: input file /var/folders/bs/g9p_b6h14w5_pv_j3ztyxcxw0000gn/T/build237949294981430414.tmp/Blink.cpp.hex contains 1078 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.05s

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0088
         0xff != 0x10
avrdude: verification error; content mismatch

avrdude done.  Thank you.


I am getting this same error

anthonybradley
 
Posts: 6
Joined: Wed Jul 26, 2017 4:02 pm

Re: Trinket Pro 3V

by rishmamnanicodes on Thu Dec 07, 2017 1:44 am

Same type of thing is happening to me... I have the Arduino IDE and I am trying to upload the Blink code to my Trinket 3.3v Microcontroller. I have the board adafruit extention installed and I have the Trinket 8mHz selected. I have followed all the directions. (I am on MacOSX and I watched other videos on how to set up my mac for this to work. Still, I have tried to use a hub and 5 different cables. I have also pressed the button for the red light. I tried uploading the code and what do ya know? For the 10th time I get "could not find USBTiny device" Someone help or something!!! Thanks..

rishmamnanicodes
 
Posts: 1
Joined: Thu Dec 07, 2017 1:39 am

Re: Trinket Pro 3V

by Stemplin on Mon Feb 26, 2018 6:15 pm

Did you figure out a solution? I'm on my third day of trying to solve the same problem.

Stemplin
 
Posts: 1
Joined: Mon Feb 26, 2018 4:32 pm

Re: Trinket Pro 3V

by Terry5 on Mon Apr 09, 2018 6:19 pm

adafruit_support_mike wrote:The tutorial explains how to make the Pro Trinket work with the Arduino IDE:

https://learn.adafruit.com/introducing- ... rduino-ide

Hello, Im need and I'm trying to program adafruit trinket 5v to detect my tv remote 340pps and trigger buzzer at 400,500,900 hz for 5 sec or be able to let the program pick it rat eat random, Im trying to built simon says with sound and a led. I tried builting it based on this sketch. How do i make this happen?

http://learn.adafruit.com/ir-sensor/using-an-ir-sensor


T Cr

Terry5
 
Posts: 5
Joined: Mon Apr 09, 2018 6:06 pm

Re: Trinket Pro 3V

by Terry5 on Mon May 27, 2019 11:56 pm

I was able to upload sketches to my Trinket 5v now, I'm running into programming problems. I will try to keep this positive by saying I brought an ardunio uno,nano once I finally achieve this this goal "that's it" . I have attached two sketches the first sketch I was trying to use the const int and pin 0 to light an led at 3.0 v speaker on pin 1 for ir detector on pin2 pin 3 ir detector tones on pin 4 to sound for 30 seconds of less at specified frequency. sketch two again use const int for speed/less delay and to try and repeat what is being detected and sound the speaker at different pulse rate, This was my goal to work around the first problem, I would love to join everyone here with the passion of programming and home automation with Tebow cloud" not for me and takes too much time". Enjoy

Thank You
Terry5
Attachments
sketch_apr11_repeater.ino
(3.94 KiB) Downloaded 27 times
sketch_may27a_retry.ino
(3.55 KiB) Downloaded 27 times

Terry5
 
Posts: 5
Joined: Mon Apr 09, 2018 6:06 pm

Re: Trinket Pro 3V

by franklin97355 on Tue May 28, 2019 12:16 am

First off if you don't plan to change the value of an object you should not make it a variable.
Code: Select all | TOGGLE FULL SIZE
int SPEAKERPIN = 0;    // Piezo speaker on Trinket/Gemma Pin GPIO #0/D0

int ledPin = 1;      // LED connected to digital pin 1

int analogPin = 2;   // potentiometer connected to analog pin 2

int val = 0;         // variable to store the read value

int IRledPin = 3;      // LED connected to digital pin 3

int analog2Pin = 4;   // potentiometer connected to analog pin 4
would be better as
Code: Select all | TOGGLE FULL SIZE
#define SPEAKERPIN  0    // Piezo speaker on Trinket/Gemma Pin GPIO #0/D0
#define ledPin  1      // LED connected to digital pin 1
#define analogPin  2   // potentiometer connected to analog pin 2
#define IRledPin  3      // LED connected to digital pin 3
#define analog2Pin  4   // potentiometer connected to analog pin 4

int val = 0;         // variable to store the read value



franklin97355
 
Posts: 21217
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Trinket Pro 3V

by Terry5 on Fri May 31, 2019 3:26 am

I would like to thank you Franklin for your help, my Main goal was to place the sketch from your adafruit website on to my trinket 5v and make the speaker make a different sound base on the irpin 2 or 3 ircode being received. I believe this has one error redefine unit16_t,moreover; on that correction you made does pasting the everything together speed-up the processing time and could I change analog to digital read or write?

Code: Select all | TOGGLE FULL SIZE
  // We need to use the 'raw' pin reading methods because timing is very important here
// and the digitalRead() procedure is slower!
#define IRpin_PIN2 PIN2 // ATTiny85 had Port B pins
#define IRpin_PIN3 PIN3 // ATTiny85 had Port B pins
#define LEDpin     4    // LED - osram on Pin GPIO #4 / D4
#define IRpin      3    // IR sensor - TSOP38238 on Trinket/Gemma 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 LEDpin     0   // Piezo speaker on Trinket/Gemma Pin GPIO #1/D0
 
#define MAXPULSE    400  // the maximum pulse we'll listen for - 5 milliseconds
#define NUMPULSES    2  // 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[2][2];   // pair is high and low pulse
uint16_t currentpulse = 0; // index for pulses we're storing
uint32_t irCode = 0;
 
void setup() {
  #define IRpin_PIN2 PIN2 // ATTiny85 had Port B pins
  #define IRpin_PIN3 PIN3 // ATTiny85 had Port B pins
  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(LEDpin,     OUTPUT); // Output tones 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==0xe0c8A2DD)  {      // "1" on my remote, USE YOUR CODE HERE
    beep(SPEAKERPIN,400,500); }  // Make a 400 Hz beep
  else if (irCode==0xe0c8a3dc) { // "2", USE YOUR OWN HEX CODE HERE
    beep(SPEAKERPIN,500,500); }  // Make a 500 Hz beep
  else if (irCode==0xe0c8a41b) { // "3", USE YOUR OWN HEX CODE HERE
    beep(SPEAKERPIN,600, 500); } // Make a 600 Hz beep
  else if (irCode==0xe0c8a29d) { // "4", USE YOUR OWN HEX CODE HERE
    beep(SPEAKERPIN, 700, 500);  // Make a 700 Hz beep
     
  }
  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==0xe0c8A2DD)  {      // "1" on my remote, USE YOUR CODE HERE
    beep(SPEAKERPIN,400,500); }  // Make a 400 Hz beep
  else if (irCode==0xe0c8a3dc) { // "2", USE YOUR OWN HEX CODE HERE
    beep(SPEAKERPIN,500,500); }  // Make a 500 Hz beep
  else if (irCode==0xe0c8a41b) { // "3", USE YOUR OWN HEX CODE HERE
    beep(SPEAKERPIN,600, 500); } // Make a 600 Hz beep
  else if (irCode==0xe0c8a29d) { // "4", USE YOUR OWN HEX CODE HERE
    beep(SPEAKERPIN,700, 500);  // 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_PIN2 & _BV(IRpin)) { // got a high pulse
      highpulse++;
      delayMicroseconds(RESOLUTION);
      if (((highpulse >= MAXPULSE) && (currentpulse != 0))|| currentpulse == NUMPULSES) {
        return currentpulse;
      }
   }
   pulses[currentpulse][0] = highpulse;

   while (! (IRpin_PIN2 & _BV(IRpin))) { // got a low pulse
      lowpulse++;
      delayMicroseconds(RESOLUTION);
      if (((lowpulse >= MAXPULSE) && (currentpulse != 0))|| currentpulse == NUMPULSES) {
        return currentpulse;
      }
   }
   pulses[currentpulse][1] = lowpulse;
   currentpulse++;
  }

   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==0xe0c8A2DD)  {      // "1" on my remote, USE YOUR CODE HERE
    beep(SPEAKERPIN,400,500); }  // Make a 400 Hz beep
  else if (irCode==0xe0c8a3dc) { // "2", USE YOUR OWN HEX CODE HERE
    beep(SPEAKERPIN,500,500); }  // Make a 500 Hz beep
  else if (irCode==0xe0c8a41b) { // "3", USE YOUR OWN HEX CODE HERE
    beep(SPEAKERPIN,600, 500); } // Make a 600 Hz beep
  else if (irCode==0xe0c8a29d) { // "4", USE YOUR OWN HEX CODE HERE
    beep(SPEAKERPIN, 700, 500);  // Make a 700 Hz beep
  }
  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==0xe0c8A2DD)  {      // "1" on my remote, USE YOUR CODE HERE
    beep(SPEAKERPIN,400,500); }  // Make a 400 Hz beep
  else if (irCode==0xe0c8a3dc) { // "2", USE YOUR OWN HEX CODE HERE
    beep(SPEAKERPIN,500,500); }  // Make a 500 Hz beep
  else if (irCode==0xe0c8a41b) { // "3", USE YOUR OWN HEX CODE HERE
    beep(SPEAKERPIN,600, 500); } // Make a 600 Hz beep
  else if (irCode==0xe0c8a29d) { // "4", USE YOUR OWN HEX CODE HERE
    beep(SPEAKERPIN,700, 500);  // 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_PIN2 & _BV(IRpin)) { // got a high pulse
      highpulse++;
      delayMicroseconds(RESOLUTION);
      if (((highpulse >= MAXPULSE) && (currentpulse != 0))|| currentpulse == NUMPULSES) {
        return currentpulse;
      }
   }
   pulses[currentpulse][0] = highpulse;

   while (! (IRpin_PIN2 & _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);
          } 

         
}

// 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_PIN3 & _BV(IRpin)) { // got a high pulse
      highpulse++;
      delayMicroseconds(RESOLUTION);
      if (((highpulse >= MAXPULSE) && (currentpulse != 0))|| currentpulse == NUMPULSES) {
        return currentpulse;
      }
   }
   pulses[currentpulse][0] = highpulse;

   while (! (IRpin_PIN2 & _BV(IRpin))) { // got a low pulse
      lowpulse++;
      delayMicroseconds(RESOLUTION);
      if (((lowpulse >= MAXPULSE) && (currentpulse != 0))|| currentpulse == NUMPULSES) {
        return currentpulse;
      }
   }
   pulses[currentpulse][1] = lowpulse;
   currentpulse++;
  }

   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==0xe0c8A2DD)  {      // "1" on my remote, USE YOUR CODE HERE
    beep(SPEAKERPIN,400,500); }  // Make a 400 Hz beep
  else if (irCode==0xe0c8a3dc) { // "2", USE YOUR OWN HEX CODE HERE
    beep(SPEAKERPIN,500,500); }  // Make a 500 Hz beep
  else if (irCode==0xe0c8a41b) { // "3", USE YOUR OWN HEX CODE HERE
    beep(SPEAKERPIN,600, 500); } // Make a 600 Hz beep
  else if (irCode==0xe0c8a29d) { // "4", USE YOUR OWN HEX CODE HERE
    beep(SPEAKERPIN, 700, 500);  // Make a 700 Hz beep
  }
  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==0xe0c8A2DD)  {      // "1" on my remote, USE YOUR CODE HERE
    beep(SPEAKERPIN,400,500); }  // Make a 400 Hz beep
  else if (irCode==0xe0c8a3dc) { // "2", USE YOUR OWN HEX CODE HERE
    beep(SPEAKERPIN,500,500); }  // Make a 500 Hz beep
  else if (irCode==0xe0c8a41b) { // "3", USE YOUR OWN HEX CODE HERE
    beep(SPEAKERPIN,600, 500); } // Make a 600 Hz beep
  else if (irCode==0xe0c8a29d) { // "4", USE YOUR OWN HEX CODE HERE
    beep(SPEAKERPIN,700, 500);  // 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_PIN3 & _BV(IRpin)) { // got a high pulse
      highpulse++;
      delayMicroseconds(RESOLUTION);
      if (((highpulse >= MAXPULSE) && (currentpulse != 0))|| currentpulse == NUMPULSES) {
        return currentpulse;
      }
   }
   pulses[currentpulse][0] = highpulse;

   while (! (IRpin_PIN2 & _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);
          } 

         
}

         
Attachments
sketch_may31b.ino
(11.01 KiB) Downloaded 19 times

Terry5
 
Posts: 5
Joined: Mon Apr 09, 2018 6:06 pm

Please be positive and constructive with your questions and comments.