I've made this little "starter" code, based on an example from Arduino IDE :
const int ledPin = 13;
int ledState = LOW;
unsigned long previousMillis = 0;
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
unsigned long currentMillis = millis();
int interval = map(analogRead(0), 0, 1024, 1000, 10);
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (ledState == LOW) {
ledState = HIGH;
} else {
ledState = LOW;
}
digitalWrite(ledPin, ledState);
}
}
It is a little nothing, but a really good starting point for my Master Clock generator for my modular synth.
My question is that is it possible, somehow, make the LED just pulse, instead of blink?
Right now, it is either on or off, my target is to make it just "pulse", around 7 ms long.
I saw a video on youtube, but there was no code example unfortunately :S
Actually, that will be more than 7 ms because of the overhead of the delay command and the second digitalWrite command. If you really exactly 7ms you may be able to achieve it but you would need to play with the "7" and view the pulsing with an oscilloscope.
Wow, it is soooo simple, thank you JaBa!!!
You've just made my day.
Ok, next problem
I've expanded my code, with another pot.
As you can see, the pot generates a number between 10 and 100, and compares it into a random generated number (0-100) every time if "tick" is HIGH.
If "density" bigger than "comparator" then it sends a "pulse" to digital out 4.
The problem is that it is not working...
I think the problem is that I'd like write them in the same time maybe?
const int tick = 3;
const int tock = 4;
int tickState = LOW;
int tockState = LOW;
unsigned long previousMillis = 0;
void setup() {
pinMode(tick, OUTPUT);
pinMode(tock, OUTPUT);
Serial.begin(9600);
}
void loop() {
unsigned long currentMillis = millis();
int clockspeed = map(analogRead(0), 0, 1024, 1000, 10);
if (currentMillis - previousMillis >= clockspeed) {
previousMillis = currentMillis;
if (tickState == LOW) {
tickState = HIGH;
digitalWrite(tick, tickState);
delay(7);
digitalWrite(tick, LOW);
} else {
tickState = LOW;
}
Serial.println(clockspeed);
}
}
void loop2 (){
if (tickState = HIGH) {
int comparator = random (0,100);
int density = map(analogRead(1), 0, 1024, 10, 100);
if (comparator < density) {
digitalWrite(tock, HIGH);
delay(7);
digitalWrite(tock, LOW);
} else {
tockState = LOW;
}
}
}
"tick = HIGH" is an assignment, and because "HIGH" is non-zero, the value of the expression is always true.
In other words, the "if" is redundant - the following code will always be executed.
AWOL:
"tick = HIGH" is an assignment, and because "HIGH" is non-zero, the value of the expression is always true.
In other words, the "if" is redundant - the following code will always be executed.
I see.
Could you change it, as an example, for a n00b
AWOL:
But, as you can see, you've introduced a delay into a blink without delay.
Right? With a 7 millisecond full-stop in processing, the highest frequency this synth can handle is 140 hertz. This is a very bass instrument, like piano keys 30 and below.
encoderaudio:
... Could you change it, as an example, for a n00b
You'll only be a noob your first day ea, so jump right in. AWOL is suggesting that you look at the code you have already posted, and see if you can use the millis()-previousMillis timing loop to also change the time between turning the output on and off, thus getting rid of that toxic "delay(7);" statement. That alone limits your timing to a very low frequency. It's a D3 note.
What are you trying to do - make an audio frequency, or make a time standard that other devices will use to synchronize their noisemaking?
ChrisTenone:
Right? With a 7 millisecond full-stop in processing, the highest frequency this synth can handle is 140 hertz. This is a very bass instrument, like piano keys 30 and below.
You'll only be a noob your first day ea, so jump right in. AWOL is suggesting that you look at the code you have already posted, and see if you can use the millis()-previousMillis timing loop to also change the time between turning the output on and off, thus getting rid of that toxic "delay(7);" statement. That alone limits your timing to a very low frequency. It's a D3 note.
What are you trying to do - make an audio frequency, or make a time standard that other devices will use to synchronize their noisemaking?
Yes, I'd like to make a clock generator, which send 7 ms pulses to my modular synth. The pot should change the frequency of the pulsing, between 10 ms and 1 sec. (cca.)
encoderaudio:
Yes, I'd like to make a clock generator, which send 7 ms pulses to my modular synth. The pot should change the frequency of the pulsing, between 10 ms and 1 sec. (cca.)
Sooo,
You want an output that looks like this:
Right?
And the the seven millisecond timing is important to ... what level? Since you can time with either milliseconds or microseconds, a precision of a hundred ppm or so seems like a reasonable limit.
And the the seven millisecond timing is important to ... what level? Since you can time with either milliseconds or microseconds, a precision of a hundred ppm or so seems like a reasonable limit.
That is right Chris, that is the target.
7 ms...you know, I just sad something. 10 ms is also OK.
Modern Buchlas using 4 ms triggers, in Eurorack modular the average is (I would say) 2-10 ms.
Basically, 7 was just a number, not critical, but it should be constant.