Show Posts
Pages: [1] 2 3 ... 8
1  Using Arduino / Programming Questions / How to repeat Serial.println? on: November 09, 2013, 01:33:44 pm
Hi,
I have an IR arduino project, but there is one thing i'd like to know:
how can i, after a remote press, make the Serial.println repeat itself the same code again and again every 5 seconds,
like, if a code is received in a serial monitor,
i want that same code to repeat itself every 5 seconds
heres the code:

Code:
/* Raw IR decoder sketch!
 
 This sketch/program uses the Arduno and a PNA4602 to
 decode IR received. This can be used to make a IR receiver
 (by looking for a particular code)
 or transmitter (by pulsing an IR LED at ~38KHz for the
 durations detected
 
 Code is public domain, check out www.ladyada.net and adafruit.com
 for more tutorials!
 */
 
// We need to use the 'raw' pin reading methods
// because timing is very important here and the digitalRead()
// procedure is slower!
//uint8_t IRpin = 2;
// Digital pin #2 is the same as Pin D2 see
// http://arduino.cc/en/Hacking/PinMapping168 for the 'raw' pin mapping
#define IRpin_PIN      PIND
#define IRpin          2
 
// the maximum pulse we'll listen for - 65 milliseconds is a long time
#define MAXPULSE 65000
 
// what our timing resolution should be, larger is better
// as its more 'precise' - but too large and you wont get
// accurate timing
#define RESOLUTION 20
 
// we will store up to 100 pulse pairs (this is -a lot-)
uint16_t pulses[100][2];  // pair is high and low pulse
uint8_t currentpulse = 0; // index for pulses we're storing
 
void setup(void) {
  Serial.begin(9600);
  Serial.println("Ready to decode IR!");
}
 
void loop(void) {
  uint16_t highpulse, lowpulse;  // temporary storage timing
  highpulse = lowpulse = 0; // start out with no pulse length
 
 
//  while (digitalRead(IRpin)) { // this is too slow!
    while (IRpin_PIN & (1 << IRpin)) {
     // pin is still HIGH
 
     // count off another few microseconds
     highpulse++;
     delayMicroseconds(RESOLUTION);
 
     // If the pulse is too long, we 'timed out' - either nothing
     // was received or the code is finished, so print what
     // we've grabbed so far, and then reset
     if ((highpulse >= MAXPULSE) && (currentpulse != 0)) {
       printpulses();
       currentpulse=0;
       return;
     }
  }
  // we didn't time out so lets stash the reading
  pulses[currentpulse][0] = highpulse;
 
  // same as above
  while (! (IRpin_PIN & _BV(IRpin))) {
     // pin is still LOW
     lowpulse++;
     delayMicroseconds(RESOLUTION);
     if ((lowpulse >= MAXPULSE)  && (currentpulse != 0)) {
       printpulses();
       currentpulse=0;
       return;
     }
  }
  pulses[currentpulse][1] = lowpulse;
 
  // we read one high-low pulse successfully, continue!
  currentpulse++;
}
 
void printpulses(void) {
  Serial.println("\n\r\n\rReceived: \n\rOFF \tON");
  for (uint8_t i = 0; i < currentpulse; i++) {
    Serial.print(pulses[i][0] * RESOLUTION, DEC);
    Serial.print(" usec, ");
    Serial.print(pulses[i][1] * RESOLUTION, DEC);
    Serial.println(" usec");
  }
}

and here is the part i want to copy itself every 5 seconds:
like, if a code is received in a serial monitor,
i want that same code to repeat itself every 5 seconds


Code:
 Serial.println("\n\r\n\rReceived: \n\rOFF \tON");
  for (uint8_t i = 0; i < currentpulse; i++) {
    Serial.print(pulses[i][0] * RESOLUTION, DEC);
    Serial.print(" usec, ");
    Serial.print(pulses[i][1] * RESOLUTION, DEC);
    Serial.println(" usec");
2  Topics / Education and Teaching / what are ohms? im new at this on: January 12, 2012, 12:44:43 pm
?
3  Community / Exhibition / Gallery / Re: my 11th arduino project: UFO + Algebre on: January 10, 2012, 05:17:12 pm
thanks  smiley-grin
good luck for ur project,
send me the link of ur video after u finished ur project  smiley-mr-green smiley-mr-green smiley-mr-green
4  Community / Exhibition / Gallery / my 11th arduino project: UFO + Algebre on: January 09, 2012, 04:38:06 pm
5  Community / Exhibition / Gallery / Re: Arduino Ultrasonic Dimmer on: January 09, 2012, 12:44:49 pm
let me guesse,
u use pin 10 for the brightness of the lcd
but what whats the name of ur ultrasonic range finder?
6  Community / Exhibition / Gallery / Re: my 10th arduino project: playing with colours on: January 05, 2012, 11:33:35 am
do i have 1? smiley-eek-blue

im just trying to find one, and also, im filming myself with a webcam  smiley-small
7  Community / Exhibition / Gallery / my 10th arduino project: playing with colours on: January 04, 2012, 04:09:03 pm
hi all,
i used processing
8  Using Arduino / Project Guidance / Re: Need project ideas on: January 04, 2012, 02:57:58 pm
ok,
ill do the UFO stuff,
pretty much awsome with my old meccano
thanks
9  Using Arduino / Project Guidance / Re: Need project ideas on: January 04, 2012, 12:20:36 pm
ok,
i admit i suck in english, as its my third language,
but anyway,
i want to make something that could be usful in life,
i finished something like controlling 5 leds using processing,
but its i dont feel like doing something because its not really usful <-(i dont know if usful is written like that)
10  Using Arduino / Project Guidance / Re: Need project ideas on: January 03, 2012, 05:05:49 pm
already doned with my 1st project
11  Using Arduino / Project Guidance / Re: Need project ideas on: January 03, 2012, 04:31:36 pm
my dad would'nt sell any of my stuff either he woud'nt buy me anything else,

he said that i have enough things
12  Using Arduino / Project Guidance / Need project ideas on: January 03, 2012, 03:53:23 pm
hi everyone, smiley-grin
i only doned one project in those holidays, smiley-sad
only 7 days are remaing before school start over again,  smiley-eek

so i need ANY idea for projects  with arduino, smiley-eek
the idea project in the website are not helping me
those are the things i have;

1 lcd shield
1 servo motor
9 motors
1 ping sensor
alot of junmper wires
1 laser light
10 blue leds
10 white leds
10 red leds
10 yellow leds
10 green leds
8 swithes
6 bulbs
8 low quality solar energy panels
6 speakers
alot of resistors

P.S.
the thing of my arduino that receives 9 volts from a wire is broken/deteached;   smiley-roll-sweat
so i will need a project so that the arduino is pluged to my laptop.   smiley-mr-green

and dont tell me projects that i have already doned on my videos.

thanks in advance  
 smiley-lol smiley-lol smiley-lol smiley-lol smiley-lol smiley-lol smiley-lol


13  Using Arduino / Programming Questions / Re: how to control arduino from processing. NEED HELP!!! on: December 30, 2011, 06:24:12 pm
it finally worked  smiley-grin smiley-grin smiley-grin
i only had to configure that thisPort was COM4,
thanks guys for helping me   smiley-yell
14  Using Arduino / Programming Questions / Re: how to control arduino from processing. NEED HELP!!! on: December 30, 2011, 01:47:27 pm
i hace three COM
COM1
COM3
COM4,

COM 1 us the communication port,
COM 4 is the arduino port,
COM 3, i have no idea.

but still, should i configure processing to make it COM1 for comunication, or is it already done?
15  Using Arduino / Programming Questions / Re: how to control arduino from processing. NEED HELP!!! on: December 30, 2011, 01:34:21 pm
i copied and pasted the arduino code listed in processing sketches to arduino software,

i uploaded the code,

i run the processing skethes,

nothing is working but they could communicate each other

i tried that for all 5 serial I/O sketches
Pages: [1] 2 3 ... 8