Show Posts
Pages: [1] 2 3 ... 18
1  Using Arduino / Programming Questions / Re: time lapse dolly code problems on: May 23, 2014, 04:47:46 am
  if ((buttonState = digitalRead(buttonPin)) == HIGH)
Are you sure this is what you wanna do?
2  Using Arduino / Programming Questions / Re: I need help with sequence with millis() on: May 21, 2014, 06:15:18 am
the noteCount and the durCount will be the same length, so you'll need only one of them (maybe the noteCount).

then you can use the for loop like before, but use the pointers to your arrays. Something like

for (int x = 0; x < noteCount; x++) {
    noteOn(0x90, mynote[x], 0x45);   // send note
    delay(dur[x]);                   // wait corresponding delay
    noteOn(0x80, mynote[x], 0x00);   // send "noteOff"
but you should replace that delay() with the "delay" idea from the BlinkWithoutDelay example.

What you need to do, is in the right places use the pointers. So for the notes you "point" to the mynote array, for the durations you "point" to the dur array,...
3  Using Arduino / Programming Questions / Re: Assistance in diploma. Question programming the Arduino mega on: May 21, 2014, 03:04:05 am
so step one getting rid of the delays() and step two using the state change idea to increment the count variable.
a bit of work to be done...
4  Using Arduino / Programming Questions / Re: I need help with sequence with millis() on: May 21, 2014, 01:52:10 am
i remember i also had some trouble understanding Arrays. But when you get the hang of it, you will see they are really useful and not so difficult to use!

In your case, you could even use an array for the notes, another for the velocities and another for the durations (if needed!), to have some more practice on using arrays...
This would allow you to play a melody with rhythm and dynamics. Not bad...
5  Using Arduino / Programming Questions / Re: scketch in scketch on: May 21, 2014, 01:48:47 am
I'm not sure i understood right, but maybe what you are looking is a State Machine.
State Machines work like this:
   You create "States", let's say for example there are 3 States.
   when your sketch starts the State is 1 and things work a certain way.
   then when you press a button State becomes State 2 and it can work in a different way.
   Then press again and State becomes State 3 and your sketch can still so something different.

The sketch would look something like this:
// all your variables and other needed stuff here

byte State = 0; // we will have 3 States; State 0, State 1 and State 2
                // we start with State = 0

void setup(){
  // all your setup code here

void loop(){

  // check your button
  // if the button was pressed
    // increase State by 1
    // if State is equal to 3, make it again equal to 0     - we are using only 3 States

  // Check current State and run only the appropriate code
  // if State is equal to 0 run just State0 code
  if (State == 0) {
    // Your State0 code here
  // if State is equal to 1 run just State1 code
  if (State == 1) {
    // Your State1 code here
  // if State is equal to 2 run just State2 code
  if (State == 2) {
    // Your State2 code here

State Machines are very useful and allow you to run specific pieces of code (you can kind of think of them as little sketches) according to the State the sketch is currently in.
I hope you got the idea of what i meant, if not just let us know and we can try to explain it better. If you look for State Machine in google you will find a lot of results which might also help you.
6  Using Arduino / Programming Questions / Re: I need help with sequence with millis() on: May 21, 2014, 01:30:13 am
yep, like Henry-Best said, the trick using arrays is that to access each of the elements of the array you have to use a pointer, something like:
mynote[1] //would be note 77, the second element of your mynote array
Then, by using a for loop, you can access all of the notes in a sequence.

one other idea...
You are sending both your noteOn and your noteOff like this:
noteOn(0x90, mynote, 0x45);
You are always using as first parameter for your function 0x90. 0x90 is the MIDI noteOn command, so that is fine to send when you want to play a note (send a noteOn command).

But the way you are doing things now you aren't really sending a noteOff, you are just sending a noteOn with 0 velocity (0 "volume"), which kind of "sounds" the same.
But I would suggest that you change that and use the MIDI noteOff command: 0x80.

Here is a nice page with some useful information about MIDI protocol:

7  Using Arduino / Programming Questions / Re: I need help with sequence with millis() on: May 18, 2014, 11:45:37 pm
i think a possible solution would be to create an array with the sequence you need.

Then you could send note[n],
wait as long as you need (if possible without using the delay()  ),
stop note[n] and play note[n+1],
wait, stop note[n+1] and play note[n+2],
and so on...

I have used this before and it worked great. You can make arrays for scales, melodies and even for the rhythm (durations).
8  Using Arduino / Programming Questions / Re: LCD Screen countdown timer problem and input problem on: May 18, 2014, 01:36:03 pm
i would suggest you don't use the delay() function on your program.
The delay() function is a blocking function, which meant that whenever you are using it NOTHING else can happen. For instance you can read any inputs.
A solution would be to use the idea from the BlinkWithoutDelay sketch. You can find it on your IDE or here:

It is a simple idea. save the time ( millis() ) of an event into a variable. this way you can always compare it with the current time and see how much time has passed. If, for instance, a second as passed, then do something...
Take a look to the link above, i think you will understand it better...
9  Using Arduino / Programming Questions / Re: help with understanding millis on: May 18, 2014, 02:27:17 am
I'm a newbie myself, I understand it is frustrating coming to the forum for assistance and being told that you need to read a tutorial and figure it out.  If you understood the tutorial you wouldn't have asked the question (a reasonable assumption.) 
Instead of telling you what you already know that you don't understand, I thought I'd learn with you and maybe help you get to the final solution a little quicker.
So you think it is better to give the answer to someone than to tell them where they can find the info and learn on their own?!
If you stick around for a while in the forum, you will notice that most people will ask before they try to learn on their own. And this thread is a great example. There are probably HUNDREDS of threads in this forum alone explaining how millis() works, telling people where they can find more information about it and even some code examples and solutions to problems.

I think reading (watching,...), understanding, and then writing your own code has much better results (maybe not so immediate, but if you want no work at all just buy a ready made product!  smiley-wink    )...
10  Using Arduino / Programming Questions / Re: help with understanding millis on: May 18, 2014, 12:00:05 am
you should take a look at the BlinkWithoutDelay example.
You can find it on your IDE or here:

the idea would be something like this:
Define an interval (you said you want 5s).
You would need to save the millis() into a variable at the moment you want the Arduino so start counting the 5s (ex: when the door is opened).
Then on each loop you can check if the difference between the previous millis() (which you save into a variable) and the current millis() is equal or bigger than you interval. In other words: you can on each loop check if 5 seconds have passed.

It would be something like this:
(i'm skipping parts of code, just writing the relevant for the "interval checking, but nothing for the door,...)
// create variables
long openTime;
int interval = 5000;

// ...

// open the door
   // save time at which door was opened
   openTime = millis();

// if the door is open
   // check for interval
   if( millis() - openTime > interval) {
      // close the door

Good luck!
11  Using Arduino / Programming Questions / Re: Arduino UNO reiniciando [ Arduino UNO restarting ] on: May 10, 2014, 01:44:42 am
Temos aqui no forum uma secção só para perguntas e problemas em português.    smiley-wink

Para o podermos ajudar, vai ter de nos mostrar o código que está a utilizar (utilize as tags CODE ) e dizer como está a ligar tudo.
Aconselho a experimentar alguns dos exemplos do IDE do Arduino, como o Blink, por exemplo.
Good luck!

We also have here in the forum a section for questions and problem solving in Portuguese!

So we can help you, you should post your code (using the CODE tags) e tell us how you're connecting everything.
I advise you also to try the example that come with the Arduino IDE, like for instance the Blink example.
Good luck.
12  Using Arduino / Programming Questions / Re: Arduino - MODBUS - Lib. problem. on: May 10, 2014, 01:28:00 am
First of all, i would like to remind you that you should always use the CODE tags (# sign up there on the menu buttons) when posting your code.

A question for you. Did you write this code yourself or did you copy it from somewhere?
I see right on the beginning something strange with your comments. Just before you start the big comment you use
// code below.
but i think you should be using
/* code below.

I also don't see you adding the library. You have the #include command:
...but there is the library missing, something like
#include <ModbusMaster.h>

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Yes it would. So why don't you turn the verbose on and shows us that output. It is quite helpful to find out what the problems are...

Good luck with your project!
13  Using Arduino / Programming Questions / Re: Why do I have to burn the bootloader to my UNO r3 so often? on: May 10, 2014, 01:16:29 am
try to get a friend to let you try with his UNO and see if things are different.

Or build your own "breadboard UNO". They aren't difficult not expensive to build, and can be a lot of fun!
14  Using Arduino / Programming Questions / Re: Moving string position in array on: May 09, 2014, 01:14:26 pm
why do you need the "int time" parameter in the alarmHandler function if then you're not using it?
void alarmHandler(char messageIn, int time){
  for (int i = 51; i > 0; i--){
    messageArray[i] = messageArray[i-1];
  messageArray[0] = messageIn;

is that your whole code? I'm note sure what you are trying to do...
15  Using Arduino / Programming Questions / Re: Why do I have to burn the bootloader to my UNO r3 so often? on: May 09, 2014, 01:05:50 am
you say the sketches don't "work properly". What exactly happens? What is the problem? Is it always the same?
Pages: [1] 2 3 ... 18