My next project is a Laser tag system

What are you developing?
User avatar
mrburnette
Posts: 1774
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: My next project is a Laser tag system

Postby mrburnette » Mon May 11, 2015 2:31 am

ahull wrote:There are a number of existing IR libraries for Arduino for example...
http://shirriff.github.io/Arduino-IRremote/


I have used pmalmsten code too, an easy implementation I used long ago on an ATtiny85
http://www.hackster.io/rayburne/infrared-dedicated-decoder


Ray

victor_pv
Posts: 1077
Joined: Mon Apr 27, 2015 12:12 pm

Re: My next project is a Laser tag system

Postby victor_pv » Mon May 11, 2015 4:08 am

Thank you guys for the links. I have to look at those.
I just got a few high power leds, I need to test a driver circuit to see if I can pulse and detect it fast enough, and then start with some actual communication, and those examples will come handy :)

User avatar
robert94
Posts: 7
Joined: Sun Jul 03, 2016 11:31 pm
Location: Vietnam

Re: My next project is a Laser tag system

Postby robert94 » Mon Nov 28, 2016 11:31 am

mrburnette wrote:
ahull wrote:There are a number of existing IR libraries for Arduino for example...
http://shirriff.github.io/Arduino-IRremote/


I have used pmalmsten code too, an easy implementation I used long ago on an ATtiny85
http://www.hackster.io/rayburne/infrared-dedicated-decoder


Ray

Dear mrburnette,
I follow http://www.hackster.io/rayburne/infrared-dedicated-decoder and this is my code:

Code: Select all

int irPin     = PA0;       //Sensor pin 1 wired to Arduino's pin D4
int statLED   = PC13;       //Toggle the status LED every time Power is pressed
int start_bit = 2200;    //Start bit threshold (Microseconds)
int bin_1     = 1000;    //Binary 1 threshold (Microseconds)
int bin_0     = 400;     //Binary 0 threshold (Microseconds)

void setup() {
  pinMode(statLED, OUTPUT);
  digitalWrite(statLED, LOW);

  pinMode(irPin, INPUT);

  Serial.begin(9600);
  Serial.println("IR/Serial Initialized: ");
}

void loop() {
  int key = getIRKey();   //Fetch the key
 
  if(key != 0)            //Ignore keys that are zero
  {
    switch(key)
    {
      case 128: Serial.print("1"); break;
      case 129: Serial.print("2"); break;
      case 130: Serial.print("3"); break;
      case 131: Serial.print("4"); break;
      case 132: Serial.print("5"); break;
      case 133: Serial.print("6"); break;
      case 134: Serial.print("7"); break;
      case 135: Serial.print("8"); break;
      case 136: Serial.print("9"); break;
      case 137: Serial.print("0"); break;
     
      case 144: Serial.print("A"); break;  // CH Up
      case 145: Serial.print("B"); break;  // CH Down
      case 146: Serial.print("C"); break;  // VOL Right
      case 147: Serial.print("D"); break;  // VOL Left
      case 148: Serial.print("E"); break;  // Mute
      case 165: Serial.print("F"); break;  // AV/TV
      case 149: Serial.print("P");         // Power == MENU ACTIVE
        //This toggles the statLED every time power button is hit
        if(digitalRead(statLED) != 1)
          digitalWrite(statLED, HIGH);
        else
          digitalWrite(statLED, LOW);
        break;

      //default: Serial.println(key); // for inspection of keycode
    }

    delay(400);    // avoid double key logging (adjustable)
  }
}

int getIRKey() {
  int data[12];
  int i;

  while(pulseIn(irPin, LOW) < start_bit); //Wait for a start bit
 
  for(i = 0 ; i < 11 ; i++)
    data[i] = pulseIn(irPin, LOW);      //Start measuring bits, I only want low pulses
 
  for(i = 0 ; i < 11 ; i++)             //Parse them
  {     
    if(data[i] > bin_1)                 //is it a 1?
      data[i] = 1;
    else if(data[i] > bin_0)            //is it a 0?
      data[i] = 0;
    else
      return -1;                        //Flag the data as invalid; I don't know what it is! Return -1 on invalid data
  }

  int result = 0;
  for(i = 0 ; i < 11 ; i++)             //Convert data bits to integer
    if(data[i] == 1) result |= (1<<i);

  return result;                        //Return key number
}


and:

Code: Select all

Sketch uses 10,856 bytes (16%) of program storage space. Maximum is 65,536 bytes.
Global variables use 2,000 bytes of dynamic memory.
stm32flash 0.4

http://stm32flash.googlecode.com/

Using Parser : Raw BINARY
Interface serial_w32: 230400 8E1
Version      : 0x22
Option 1     : 0x00
Option 2     : 0x00
Device ID    : 0x0410 (Medium-density)
- RAM        : 20KiB  (512b reserved by bootloader)
- Flash      : 128KiB (sector size: 4x1024)
- Option RAM : 16b
- System RAM : 2KiB
Write to memory
Erasing memory

Wrote address 0x08000100 (2.36%)
Wrote address 0x08000200 (4.72%)
Wrote address 0x08000300 (7.07%)
Wrote address 0x08000400 (9.43%)
Wrote address 0x08000500 (11.79%)
Wrote address 0x08000600 (14.15%)
Wrote address 0x08000700 (16.51%)
Wrote address 0x08000800 (18.87%)
Wrote address 0x08000900 (21.22%)
Wrote address 0x08000a00 (23.58%)
Wrote address 0x08000b00 (25.94%)
Wrote address 0x08000c00 (28.30%)
Wrote address 0x08000d00 (30.66%)
Wrote address 0x08000e00 (33.01%)
Wrote address 0x08000f00 (35.37%)
Wrote address 0x08001000 (37.73%)
Wrote address 0x08001100 (40.09%)
Wrote address 0x08001200 (42.45%)
Wrote address 0x08001300 (44.80%)
Wrote address 0x08001400 (47.16%)
Wrote address 0x08001500 (49.52%)
Wrote address 0x08001600 (51.88%)
Wrote address 0x08001700 (54.24%)
Wrote address 0x08001800 (56.60%)
Wrote address 0x08001900 (58.95%)
Wrote address 0x08001a00 (61.31%)
Wrote address 0x08001b00 (63.67%)
Wrote address 0x08001c00 (66.03%)
Wrote address 0x08001d00 (68.39%)
Wrote address 0x08001e00 (70.74%)
Wrote address 0x08001f00 (73.10%)
Wrote address 0x08002000 (75.46%)
Wrote address 0x08002100 (77.82%)
Wrote address 0x08002200 (80.18%)
Wrote address 0x08002300 (82.54%)
Wrote address 0x08002400 (84.89%)
Wrote address 0x08002500 (87.25%)
Wrote address 0x08002600 (89.61%)
Wrote address 0x08002700 (91.97%)
Wrote address 0x08002800 (94.33%)
Wrote address 0x08002900 (96.68%)
Wrote address 0x08002a00 (99.04%)
Wrote address 0x08002a68 (100.00%) Done.

Starting execution at address 0x08000000... done.


in Serial Monitor, i just see the "IR/Serial Initialized: ", press any key Remote and nothing happens!
please help me!!! :cry:


Return to “Projects”

Who is online

Users browsing this forum: No registered users and 1 guest