To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.nqcOpen lugnet.robotics.rcx.nqc in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / NQC / 1593
1592  |  1594
Subject: 
Happy new year!!!
Newsgroups: 
lugnet.robotics.rcx.nqc
Date: 
Sun, 4 Jan 2004 00:29:55 GMT
Viewed: 
4814 times
  
Happy new year for everybody!

I started making this program at 11:00 pm on December 31st. Incredibly, I could
finish it for 12:00 to use it.

It simulates fireworks sound using the RCX speaker. It uses lots of Random(n)
calls to make the sound different each time. (Maybe you'll need 2.0 firmware
since it uses variables for PlayTone();)

Here is the program:

#pragma noinit;
#define freqMax 1000
#define freqMin 500
int idx, freq, chng;
task main()
{
   while (true)
   {
      start xpld;
      Wait(Random(1000));
      stop xpld;
   }
}
task xpld()
{
   chng=30+(Random(4)*20);
   idx=(freqMax-freqMin)/chng;
   repeat(chng)
   {
      PlayTone(freq, 3);
      Wait(2);
      freq-=idx;
   }
   repeat(chng/3*2)
   {
      PlayTone(50+Random(200), 3);
      Wait(2);
   }
}

There are a lot of things you can change. For example, this variant uses the
remote control to change duration of the sound:

#pragma noinit;
#define freqMax 1000
#define freqMin 500
int idx, freq, chng, msg;
task main()
{   while (true)
   {
      freq=freqMax;
      until (Message() > 0);
      stop xpld;
      msg=Message();
      ClearMessage();
      start xpld;
   }
}
task xpld()
{
   chng=30+(msg*20);
   idx=(freqMax-freqMin)/chng;
   repeat(chng)
   {
      PlayTone(freq, 3);
      Wait(2);
      freq-=idx;
   }
   repeat(chng/3*2)
   {
      PlayTone(50+Random(200), 3);
      Wait(2);
   }
}





PS.: thanks Dave Baum for all your work in NQC. Hope John Hansen could help as
much as you.



Message has 2 Replies:
  Re: Happy new year!!!
 
It don't really simulate a firework but ... It's so cool :) nanobapt (21 years ago, 4-Jan-04, to lugnet.robotics.rcx.nqc)
  Re: Happy new year!!!
 
(...) thanks, at the same from me, (...) Maybe a stupid question, (haven't used NQC for a while), but can anyone tell me, why is my NQC compiler complaining that freq should be a constant ? thanks, Stef Mientki (21 years ago, 4-Jan-04, to lugnet.robotics.rcx.nqc)

5 Messages in This Thread:


Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR