Show Posts
|
|
Pages: [1] 2
|
|
3
|
Using Arduino / Audio / Re: Sound recorder/player ICs
|
on: September 16, 2012, 10:45:50 am
|
Hi Alkopop79, If you don't need hifi sound quality, ISD storage devices might be just what you are looking for. Goto: http://www.nuvoton.com/hq/enu/pages/default.aspx and click "ISD Voice IC" Also see:http://www.datasheetcatalog.com/informationstoragedevices/1/ I have been using these IC's for many years for my talking coffee makers and robots. The quality is quite good. For my coffee makers I always use ISD2560, as 1 minute is long enough to store quite some messages. As far as I know (although I never used it), pitch control is possible using very little components. Good luck, Eibert.
|
|
|
|
|
4
|
Using Arduino / Programming Questions / Re: Mathematical question
|
on: May 14, 2012, 08:23:10 am
|
Ok, I used the BlinkWithoutDelay example to find a way to get rid of the 'long delay problem': the sketch seems to work fine now. Rob, thank you for refactoring the code: it looks nicely structured now. Will insert the new randOffLONG-interval function in it again. /* As long as the Ping))) sensor doesn't detect anything at a distance closer than 200cm: - a solenoid is randomly triggered for 1 to 10 times (easy snap sequence); - when triggered, the solenoid stays powered for 0,04 seconds, than is turned off for a SHORT period, randomly between 0,05 to 1 second until the next trigger pulse - after the last pulse of a sequence, the solenoid is turned off for a LONG period, randomly between 15 minutes (900 sec) and 60 minutes (3600 sec) As soon as the Ping))) sensor detects an object at a distance of 200cm or closer: - the trigger rate of the solenoid is changed depending on detection distance (the shorter the distance, the higher the trigger frequency) - the minimum time needed to pull the solenoid core completely into its coil is 40 (0,04 seconds) Note: solenoid is connected to LedPin 13. Ping))) instructions are based upon http://www.arduino.cc/en/Tutorial/Ping (Sketch created by David A. Mellis 3 Nov 2008, modified 30 Aug 2011 by Tom Igoe) */
// Constants won't change: int pingPin = 2; // Connect SIG from the Ping))) sensor to Arduino's Digital pin 2 int ledPin = 13; // Note: the solenoid is also connected to pin 13 int limitCm = 200; // Store the limit distance
// Variables will change: long randOffSHORT = 0; // long randOffLONG = 0; long int duration, distanceCm; int ledState = LOW; // ledState used to set the LED long previousMillis = 0; // will store last time LED was updated long interval = 0; // will store the last interval
void blinkSequence() { int blinkNumber = random(1, 11); // Define how many random blinks in a sequence, in this case 1 to 10 for (int a = 0; a < blinkNumber; a ++) { randOffSHORT = random(50, 1000); // Define length of SHORT random Off period, in this case between 0,05 and 1 second digitalWrite(ledPin, HIGH); // when ledPin = HIGH, solenoid is activated delay(40); // 40 millisec is minimum time needed, to pull solenoid core completely into its coil digitalWrite(ledPin, LOW); // turn off LED, un-trigger Solenoid delay(randOffSHORT); // wait for short random period }}
void setup() { Serial.begin(9600); pinMode(ledPin, OUTPUT); // initialize the digital pin as an output. }
void loop() { pinMode(pingPin, OUTPUT); // initialize the pingPin as an OUTPUT. digitalWrite(pingPin, LOW); delayMicroseconds(2); // a short LOW pulse is given beforehand, to ensure a clean HIGH pulse: digitalWrite(pingPin, HIGH); delayMicroseconds(5); // the PING))) is triggered by a HIGH pulse of 5 microseconds. digitalWrite(pingPin, LOW); pinMode(pingPin, INPUT); // initialize the pingPin as an INPUT. duration = pulseIn(pingPin, HIGH);
distanceCm = microsecondsToCentimeters(duration);
checkLimit(); delay(100); }
void checkLimit() { if (distanceCm > limitCm){ // randomised 'easy snap sequence' is activated interval = random(900000, 3600000); // Define length of LONG random Off period, in this case between 15 (900 sec) and 60 minutes (3600 sec) unsigned long currentMillis = millis(); if(currentMillis - previousMillis > interval){ // save the last time you blinked the LED previousMillis = currentMillis; blinkSequence(); }} else // start of snap frequency that is depending on detection distance { Serial.println(distanceCm); // "increase blinking rate depending on detection distance" digitalWrite(ledPin, HIGH); // when ledPin = HIGH, solenoid is activated delay(40); // 40 millisec is minimum time necessary to pull core completely into coil digitalWrite(ledPin, LOW); // turn off LED, un-trigger Solenoid delay(40); // safety delay, as 40 millisec is the shortest possible time between triggers delay(distanceCm*distanceCm/20); // extra delay; duration will decrease quickly when approaching sensor } } long microsecondsToCentimeters(long microseconds) { return microseconds / 29 / 2; }
|
|
|
|
|
5
|
Using Arduino / Programming Questions / Re: Mathematical question
|
on: May 12, 2012, 11:00:01 am
|
|
Hi Rob,
I did not use N in my code (see my post below, dated May 11), I just used it in my first post to illustrate what I was trying to do.
I wanted the blinking speed of the Led (with a solenoid connected to the ledPin) to increase quickly, when someone approaches the sensor. To achieve this, the delay (related to the distance) had to decrease quickly when someone approaches the sensor. This code does the trick: delay(distanceCm*distanceCm/20); // extra delay; duration will decrease quickly when approaching sensor
Eibert.
|
|
|
|
|
6
|
Using Arduino / Programming Questions / Re: Mathematical question
|
on: May 11, 2012, 12:17:27 pm
|
Wow, thanks for all the interesting comments! Actually I was happy with the first answer, by Pete (el_supremo), and in the end the formula I used was: delay(distanceCm*distanceCm/20) This is works really fine; I haven't encountered any problems -with this formula...- so far. But in the mean time, I have been struggeling a lot with the sketch I was working on: it did not work properly because of something else... The problem is (see sketch below): during the randOffLONG period, the Ping))) sensor is not working as "everything is paused" due to using relay(). Therefor, I wanted to replace function delay(randOffLONG); by something that is based upon millis. But I can't find the right way to do this! Note: All other pauses that use relay() are too short to cause any problems, so I only need to find a solution for the randOffLONG period. I hope someone of you can help me out?! /* As long as the Ping))) sensor doesn't detect anything at a distance closer than 200cm: - a solenoid is randomly triggered for 1 to 10 times (easy snap sequence); - when triggered, the solenoid stays powered for 0,04 seconds, than is turned off for a SHORT period, randomly between 0,05 to 1 second until the next trigger pulse - after the last pulse of a sequence, the solenoid is turned off for a LONG period, randomly between 15 minutes (900 sec) and 60 minutes (3600 sec) As soon as the Ping))) sensor detects an object at a distance of 200cm or closer: - the trigger rate of the solenoid is changed depending on detection distance (the shorter the distance, the higher the trigger frequency) - the minimum time needed to pull the solenoid core completely into its coil is 40 (0,04 seconds) Note: solenoid is connected to LedPin 13. Ping))) instructions are based upon http://www.arduino.cc/en/Tutorial/Ping (Sketch created by David A. Mellis 3 Nov 2008, modified 30 Aug 2011 by Tom Igoe) */ int pingPin = 2; // Connect SIG from the Ping))) sensor to Arduino's Digital pin 2 int ledPin = 13; // Note: the solenoid is also connected to pin 13 int limitCm = 200; // long randOffSHORT = 0; long randOffLONG = 0; long int duration, distanceInches, distanceCm;
void setup() { Serial.begin(9600); pinMode(ledPin, OUTPUT); // initialize the digital pin as an output. }
void loop() { pinMode(pingPin, OUTPUT); // initialize the pingPin as an OUTPUT. digitalWrite(pingPin, LOW); delayMicroseconds(2); // a short LOW pulse is given beforehand, to ensure a clean HIGH pulse: digitalWrite(pingPin, HIGH); delayMicroseconds(5); // the PING))) is triggered by a HIGH pulse of 5 microseconds. digitalWrite(pingPin, LOW); pinMode(pingPin, INPUT); // initialize the pingPin as an INPUT. duration = pulseIn(pingPin, HIGH);
distanceInches = microsecondsToInches(duration); distanceCm = microsecondsToCentimeters(duration);
checkLimit(); delay(100); }
void checkLimit() { if (distanceCm > limitCm){ // randomised 'easy snap sequence' is activated randOffLONG = random(900000, 3600000); int blinkNumber = random(1, 11); for (int a = 0; a < blinkNumber; a ++) { randOffSHORT = random(50, 1000); // Define length of random Off period, in this case between 0,05 and 1 second digitalWrite(ledPin, HIGH); // when ledPin = HIGH, solenoid is activated delay(40); // 40 millisec is minimum time needed, to pull solenoid core completely into its coil digitalWrite(ledPin, LOW); // turn off LED, un-trigger Solenoid delay(randOffSHORT); // wait for short random period } delay(randOffLONG); // wait for long random period: DURING THIS PERIOD THE PING SENSOR DOES NOT RESPOND.... } else // start of snap frequency that is depending on detection distance { Serial.println(distanceCm); // "increase blinking rate depending on detection distance" digitalWrite(ledPin, HIGH); // when ledPin = HIGH, solenoid is activated delay(40); // 40 millisec is minimum time necessary to pull core completely into coil digitalWrite(ledPin, LOW); // turn off LED, un-trigger Solenoid delay(40); // safety delay, as 40 millisec is the shortest possible time between triggers delay(distanceCm*distanceCm/20); // extra delay; duration will decrease quickly when approaching sensor } }
long microsecondsToInches(long microseconds) { return microseconds / 74 / 2; }
long microsecondsToCentimeters(long microseconds) { return microseconds / 29 / 2; }
|
|
|
|
|
8
|
Using Arduino / Programming Questions / Re: Interrupt question for automated Crab Claw
|
on: May 07, 2012, 11:50:30 am
|
Hi John, I would love to get rid of Delay(). But in that case, how can I re-write the following line: delay(distanceCm*distanceCm/20) I will re-post my code between brackets, Eibert. /* As long as the Ping))) sensor doesn't detect anything at a distance closer than 200cm: - a solenoid is randomly triggered for 1 to 10 times (easy snap sequence); - when triggered, the solenoid stays powered for 0,04 seconds, than is turned off for a SHORT period, randomly between 0,05 to 1 second until the next trigger pulse - after the last pulse of a sequence, the solenoid is turned off for a LONG period, randomly between 15 minutes (900 sec) and 60 minutes (3600 sec) As soon as the Ping))) sensor detects an object at a distance of 200cm or closer: - the trigger rate of the solenoid is changed depending on detection distance (the shorter the distance, the higher the trigger frequency) - the minimum time needed to pull the solenoid core completely into its coil is 40 (0,04 seconds) Note: solenoid is connected to LedPin 13. Ping))) instructions are based upon http://www.arduino.cc/en/Tutorial/Ping (Sketch created by David A. Mellis 3 Nov 2008, modified 30 Aug 2011 by Tom Igoe) */ int pingPin = 2; // Connect SIG from the Ping))) sensor to Arduino's Digital pin 2 int ledPin = 13; // Note: the solenoid is also connected to pin 13 int limitCm = 200; // long randOffSHORT = 0; long randOffLONG = 0; long int duration, distanceInches, distanceCm;
void setup() { Serial.begin(9600); pinMode(ledPin, OUTPUT); // initialize the digital pin as an output. }
void loop() { pinMode(pingPin, OUTPUT); // initialize the pingPin as an OUTPUT. digitalWrite(pingPin, LOW); delayMicroseconds(2); // a short LOW pulse is given beforehand, to ensure a clean HIGH pulse: digitalWrite(pingPin, HIGH); delayMicroseconds(5); // the PING))) is triggered by a HIGH pulse of 5 microseconds. digitalWrite(pingPin, LOW); pinMode(pingPin, INPUT); // initialize the pingPin as an INPUT. duration = pulseIn(pingPin, HIGH);
distanceInches = microsecondsToInches(duration); distanceCm = microsecondsToCentimeters(duration);
checkLimit(); delay(100); }
void checkLimit() { if (distanceCm > limitCm){ // randomised 'easy snap sequence' is activated randOffLONG = random(900000, 3600000); int blinkNumber = random(1, 11); for (int a = 0; a < blinkNumber; a ++) { randOffSHORT = random(50, 1000); // Define length of random Off period, in this case between 0,05 and 1 second digitalWrite(ledPin, HIGH); // when ledPin = HIGH, solenoid is activated delay(40); // 40 millisec is minimum time needed, to pull solenoid core completely into its coil digitalWrite(ledPin, LOW); // turn off LED, un-trigger Solenoid delay(randOffSHORT); // wait for short random period } delay(randOffLONG); // wait for long random period } else // start of snap frequency that is depending on detection distance { Serial.println(distanceCm); // THIS IS THE FUNCTION I WOULD LIKE TO CALL USING AN INTERRUPT, "increase blinking rate depending on detection distance" digitalWrite(ledPin, HIGH); // when ledPin = HIGH, solenoid is activated delay(40); // 40 millisec is minimum time necessary to pull core completely into coil digitalWrite(ledPin, LOW); // turn off LED, un-trigger Solenoid delay(40); // safety delay, as 40 millisec is the shortest possible time between triggers delay(distanceCm*distanceCm/20); // extra delay; will decrease quickly when approaching sensor } }
long microsecondsToInches(long microseconds) { return microseconds / 74 / 2; }
long microsecondsToCentimeters(long microseconds) { return microseconds / 29 / 2; }
|
|
|
|
|
9
|
Using Arduino / Programming Questions / Interrupt question for automated Crab Claw
|
on: May 07, 2012, 11:23:37 am
|
Dear all, my Automated Crab Claw is almost working (see sketch below). The one problem I have, is that sometimes it takes (way) too long to detect someone aproaching it, as a result of using "delay()". Therefore, I thought about integrating the detection function in an interrupt routine. However: the detection function (Blinking Led: blinking rate depending on detection distance) is also using delay() and in this case I can't find a way to work around this. The attached picture shows what the random funtions are doing: this is working great. But as soon as someone is within 200cm of distance (or closer to the sensor), "increase blinking rate depending on detection distance" should take over... Here is the code, any help will be highly appreciated! /* As long as the Ping))) sensor doesn't detect anything at a distance closer than 200cm: - a solenoid is randomly triggered for 1 to 10 times (easy snap sequence); - when triggered, the solenoid stays powered for 0,04 seconds, than is turned off for a SHORT period, randomly between 0,05 to 1 second until the next trigger pulse - after the last pulse of a sequence, the solenoid is turned off for a LONG period, randomly between 15 minutes (900 sec) and 60 minutes (3600 sec) As soon as the Ping))) sensor detects an object at a distance of 200cm or closer: - the trigger rate of the solenoid is changed depending on detection distance (the shorter the distance, the higher the trigger frequency) - the minimum Note: solenoid is connected to LedPin 13. Ping))) instructions are based upon http://www.arduino.cc/en/Tutorial/Ping (Sketch created by David A. Mellis 3 Nov 2008, modified 30 Aug 2011 by Tom Igoe) */ int pingPin = 2; // Connect SIG from the Ping))) sensor Arduino's Digital pin 2 int ledPin = 13; // Note: the solenoid is also connected to pin 13 int limitCm = 200; // long randOffSHORT = 0; long randOffLONG = 0; long int duration, distanceInches, distanceCm; void setup() { Serial.begin(9600); pinMode(ledPin, OUTPUT); // initialize the digital pin as an output. } void loop() { pinMode(pingPin, OUTPUT); // initialize the pingPin as an OUTPUT. digitalWrite(pingPin, LOW); delayMicroseconds(2); // a short LOW pulse is given beforehand, to ensure a clean HIGH pulse: digitalWrite(pingPin, HIGH); delayMicroseconds(5); // the PING))) is triggered by a HIGH pulse of 5 microseconds. digitalWrite(pingPin, LOW); pinMode(pingPin, INPUT); // initialize the pingPin as an INPUT. duration = pulseIn(pingPin, HIGH); distanceInches = microsecondsToInches(duration); distanceCm = microsecondsToCentimeters(duration); checkLimit(); delay(100); } void checkLimit() { if (distanceCm > limitCm){ // randomised 'easy snap sequence' is activated randOffLONG = random(900000, 3600000); int blinkNumber = random(1, 11); for (int a = 0; a < blinkNumber; a ++) { randOffSHORT = random(50, 1000); // Define length of random Off period, in this case between 0,05 and 1 second digitalWrite(ledPin, HIGH); // when ledPin = HIGH, solenoid is activated delay(40); // 40 millisec is minimum time needed, to pull solenoid core completely into its coil digitalWrite(ledPin, LOW); // turn off LED, un-trigger Solenoid delay(randOffSHORT); // wait for short random period } delay(randOffLONG); // wait for long random period } else // start of snap frequency that is depending on detection distance { Serial.println(distanceCm); // THIS IS THE FUNCTION I WOULD LIKE TO CALL USING AN INTERRUPT, "increase blinking rate depending on detection distance" digitalWrite(ledPin, HIGH); // when ledPin = HIGH, solenoid is activated delay(40); // 40 millisec is minimum time necessary to pull core completely into coil digitalWrite(ledPin, LOW); // turn off LED, un-trigger Solenoid delay(40); // safety delay, as 40 millisec is the shortest possible time between triggers delay(distanceCm*distanceCm/20); // extra delay; will decrease quickly when approaching sensor } } long microsecondsToInches(long microseconds) { return microseconds / 74 / 2; } long microsecondsToCentimeters(long microseconds) { return microseconds / 29 / 2; }
|
|
|
|
|
11
|
Using Arduino / Programming Questions / Mathematical question
|
on: April 29, 2012, 09:18:16 am
|
|
Hi all,
I would like to use a specific delay formula, but don't know how to write it. This function: delay(distanceCm * 10) I would like to replace by the function below: delay ((N/100) raised to power 2) * 1000
So: Devide N by 100, than raise the result to power 2 than multiply this by 1000
Does anyoine of you know how to do this? Thanks in advance, Eibert
|
|
|
|
|
12
|
Using Arduino / Programming Questions / Re: Automated Crab Claw; it's working perfectly now !!!
|
on: April 21, 2012, 11:44:17 am
|
|
Hi all,
Jraskell, thanks for your advice; the sketch is working perfectly now :-) Connecting a solenoid instead of the blinking LED is no big deal, so I am really happy.
This is the sketch:
/* Randomly lights a LED for 1 to 10 times (blink sequence) When lit, the LED stays on for 0,2 seconds, than is turned off for a SHORT period, randomly between 0,1 to 2 seconds until the next blink After the last blink of a sequence, the LED is turned off for a LONG period, randomly between 5 and 10 seconds. */
int led = 13; long randOffSHORT = 0; long randOffLONG = 0;
void setup() { pinMode(led, OUTPUT); // initialize the digital pin as an output. // Pin 13 has a LED connected on most Arduino boards: }
void loop() { randOffLONG = random(5000,10000); int blinkNumber = random (1,11); for (int a = 0; a < blinkNumber; a ++){ randOffSHORT = random (100, 2000); digitalWrite(led, HIGH); // set the LED on delay(200); // wait for specified duration digitalWrite(led, LOW); // turn the LED off delay(randOffSHORT); // wait for short random period } delay(randOffLONG); // wait for long random period }
|
|
|
|
|