Author Topic: New to digispark and slightly confused!!! ir problems  (Read 7807 times)

robertiii

  • Newbie
  • *
  • Posts: 6
New to digispark and slightly confused!!! ir problems
« on: October 19, 2015, 08:59:28 pm »
So the code works...ish. It leaves the laser on for some time then it goes off. WHen you hit the button it leaves it for the short amount of time expected then off. After a short pause it then comes on again and stays on for a while. The exact code works on my UNO but not on this...

Code: [Select]
void loop() {
  buttonState = digitalRead(trigger);

  if (buttonState != lastButtonState) { //on pull of trigger
    if (lastButtonState == HIGH){
      digitalWrite(laser, HIGH);
      delay(85);
      digitalWrite(laser, LOW);
      delay(10);
 }
      lastButtonState = buttonState;
  }
  }
« Last Edit: October 19, 2015, 11:24:44 pm by robertiii »

exeng

  • Sr. Member
  • ****
  • Posts: 454
Re: New to digispark and slightly confused!!!
« Reply #1 on: October 19, 2015, 10:25:22 pm »
Are you doing anything externally to debounce your button/switch?

robertiii

  • Newbie
  • *
  • Posts: 6
Re: New to digispark and slightly confused!!!
« Reply #2 on: October 19, 2015, 11:14:36 pm »
Ok got the switch part figured out! Had to set the pinMode which I forgot and also had to add a higher ohm resistor. Now I'm working on the ir receive. What worked on my UNO once again does not work here...I have a modified ir library from here http://gammon.com.au/Arduino/IRremote_Attiny.zip. It will not recieve heres the entire code.

Code: [Select]
#include <IRremote.h>
/*Laser Gun Trigger Code
 * Laser connected to Pin 13 and ground
 * Wire runs from 5v to 220 resistor. Resistor runs to pin of push
    button. Wire from same pin as resistor to pin 2. From
    opposite pin to ground.
 */

int RECV_PIN = 0;
int irNum = 0;

int led = 2;

// Trigger stuff
int laser = 4; //Set laser to pin 13
int trigger = 3 ; //Set trigger to pin 2

//Trigger Variables
int buttonState = 1; //
int lastButtonState = 1;

int shotLim = 0;
int shotPnt = 0;

IRrecv irrecv (RECV_PIN);

decode_results results;

void irIn() {
  if (irrecv.decode(&results)) {
    switch (results.value) {
      case 2763167067:
      irNum = 5;
      break;
    }
    irrecv.resume();
  }
}

void ledBlink() {
   digitalWrite(led, HIGH);
  delay(50);
  digitalWrite(led, LOW);
  delay(50);
}
void ledSignal() {
  ledBlink();
  ledBlink();
  ledBlink();
}

void setup() {
  pinMode(laser, OUTPUT);
  pinMode(trigger, INPUT);
  pinMode(5, INPUT);
  irrecv.enableIRIn();
  ledSignal();

  while (shotLim == 0) {
    irIn();
    shotLim = irNum;
    shotPnt = shotLim;
    irNum = 0;
  }
  ledSignal();
}


void loop() {
  buttonState = digitalRead(trigger);

  if (buttonState != lastButtonState) { //on pull of trigger
    if (lastButtonState == HIGH){
      digitalWrite(laser, HIGH);
      delay(85);
      digitalWrite(laser, LOW);
      delay(10);
 }
      lastButtonState = buttonState;
  }
  }



robertiii

  • Newbie
  • *
  • Posts: 6
Re: New to digispark and slightly confused!!! ir problems
« Reply #3 on: October 20, 2015, 11:36:11 am »
The digispark does not pick up ir at all!!!!!!! The receivers work on UNO but not here! Any ideas?

robertiii

  • Newbie
  • *
  • Posts: 6
Re: New to digispark and slightly confused!!! ir problems
« Reply #4 on: October 24, 2015, 02:31:22 pm »
So is it possible to do ir on digispark? I basically need it for two applications. One is laser tag the other I need to sense a break in our beam and then do an action