Show Posts
Pages: 1 2 [3] 4 5 ... 102
31  Using Arduino / Programming Questions / Re: FSM diagrams: states and transistions on: August 18, 2014, 10:28:55 pm
The good thing that's coming out of this discussion is that states are good stuff.....
I'd say they're vital for avoiding indecipherable spaghetti code.
If you've ever written assembly language, states come naturally, otherwise you'd tie yourself up in knots within less than 100 lines, especially if your assembler program would only accept 5 character labels, as mine did. 
32  Using Arduino / Programming Questions / Re: Calculating Celsius using Datalogger on: August 18, 2014, 09:54:46 pm
@Henry_Best
Shouldn't this be *5000.0 ?
Code:
      float millivolts= (rawvoltage/1023.0) * 500.0;

Pete
Possibly. I didn't check the maths, as the OP said it was working correctly. All he wanted was to combine the two sketches.
33  Using Arduino / Programming Questions / Re: HELP! I have a program but it doesn't work on: August 18, 2014, 09:49:42 pm
Post your code between code tags (use the # key above the smileys).
Get rid of your delay()s. Use the 'blink without delay' example in the IDE.
34  Using Arduino / Programming Questions / Re: programming confusion on: August 18, 2014, 09:39:16 pm
"int left, right=0;" defines two integer variables (left and right), but only initializes "right" to zero.
If you define a variable without giving it a value, is it not automatically initialised to zero?
I was under the impression that "int x;" and "int x = 0;" were exactly the same, although the former should be avoided for the sake of clarity.
35  Using Arduino / Project Guidance / Re: ultrasonic ground speed detection on: August 18, 2014, 09:12:29 pm

I guess you could experiment with taking one of those mice to pieces and possibly replace the lens, but you'd still have the issue of needing a USB host
There were, and probably still are, ball-less mice with a PS2 connector. But I wasn't suggesting using a mouse, merely the principle of reflecting IR off the ground.
 ANY reflective system needs to take into account the surface over which it will travel. Tarmac, concrete, grass, carpet, vinyl and wood will all have different reflective properties to any wavelength of both sound and light. The OP hasn't told us anything about the surface(s) he want to use it on, so were just guessing here.
36  Using Arduino / General Electronics / Re: Safety match activation energy on: August 17, 2014, 11:21:37 pm
I saw a YouTube video where someone took nichrome wire and took a wall outlet attached to wire and managed to light a whole series of matches. I am assuming his mains was 220V, 50Hz since he didn't have any kind of plug I had ever seen before (so not US plug).
https://www.youtube.com/watch?v=3YMswqobS1g
The 2 pin plug he used is known as a Europlug and I'd guess his mains supply was 240/250V AC, which is common throughout most of Europe.  The socket he was using is not a UK socket, but looks like the type used in most of mainland Europe.
37  Using Arduino / Programming Questions / Re: FSM diagrams: states and transistions on: August 17, 2014, 11:08:49 pm
But it's a matter of one's own interpretation of the word 'state'.

Yep... or the interpretation of the convention one's following. In UML-speak it certainly seems the states are the steady parts (off, on; the boxes) and the transitions are the pathways between them (goOn, goOff; the arrows).
I think it's how you approach it. My approach is "What state is the program in?" rather than "What state is the LED in?" I can say my program is in the state of fading the LED and, only when it has completed that, it will transition to the next state.
I tend to use switch-case in my sketches. I'd find it very difficult to use fade as a transition between states.
OTOH, the LED is transitioning during the fade. You pays your money and you takes your choice!
38  Using Arduino / Programming Questions / Re: Noob, FSM timings help on: August 17, 2014, 10:49:06 pm
Quote
wait until I get myself stuck in a corner

Draw up a state diagram and / or table showing every possible Current state / Event / Transition / New state, as in my turnstile thread before you think of code. Then you won't get stuck in a corner: the coding is almost trivial compared to the thinking through of the states.
And once you've got the states sorted, you've virtually written your code.

By the way, 'turn lights', here are called 'filter lights' and can be for either left or right turning traffic. I know of one set of lights with 3 green aspects on the same pole, although two of them always come on at the same time.
39  Using Arduino / Programming Questions / Re: FSM diagrams: states and transistions on: August 17, 2014, 10:32:54 pm
I saw a link to the FSM tutorial in the playground and I don't agree with the FSM diagram for the example. I'm no expert but I'm pretty sure that two of the "states" are actually "transistions".

The first attachment below is a screen shot from the tutorial. Seems to me, that FadeIn and FadeOut are transitions: they are ways of getting from Off to On and back to Off. To my thinking the boxes are states; the arrows are the transitions.

The second attachment is my take on this, with the event causing the transition, and the transistion, attached to the arrow between two states (event/transiition), along the lines described here. So there are 4 events (Buttons ABCD) and 4 transistions (FullOn, FadeOn, FullOff, FadeOff) giving 4 arrows between the 2 states of Off and On.

I'm sure there are different conventions in FSM modeling, and it's not out of the question that a transition could be seen as a state- a Transition State- but I'd be keen to hear others' views.

Jim
I would say that the fade phase is a(n unsteady?) state until the fade has completed. Only then do you transition to the next phase. But it's a matter of one's own interpretation of the word 'state'.
40  Using Arduino / Programming Questions / Re: Planning and Implementing an Arduino Program on: August 17, 2014, 10:10:38 pm
Nice work, Robin.
41  Using Arduino / Programming Questions / Re: Calculating Celsius using Datalogger on: August 17, 2014, 09:29:04 pm
Try:
Code:
#include <SD.h>
const int chipSelect = 4;
void setup()
{
  Serial.begin(9600);
   while (!Serial) {
    ;
  }
  Serial.print("Initializing SD card...");
  pinMode(19, OUTPUT);
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    return;
  }
  Serial.println("card initialized.");
}
void loop()
{
  String dataString = "";
  for (int analogPin = 0; analogPin < 8; analogPin++) {
      int rawvoltage= analogRead(analogPin);
      float millivolts= (rawvoltage/1023.0) * 500.0;
      float celsius= millivolts - 273.15;
      dataString += String(celsius);
      dataString += ",";
      delay(100);
     }
  File dataFile = SD.open("datalog.csv", FILE_WRITE);
  if (dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    Serial.println(dataString);
  }  
  else {
    Serial.println("error opening datalog.csv");
  }
}
42  Using Arduino / Project Guidance / Re: Multiple Buttons on seperate digital inputs on: August 17, 2014, 08:53:41 pm
Code:
void loop(){
  pinState = digitalRead(pinBtn[2]);
  if(pinState == HIGH){
    digitalWrite(pinLed, HIGH);
  }else{
    digitalWrite(pinLed, LOW);
  }
}
Contracts to:
Code:
void loop(){
 digitalWrite(pinLed, digitalRead(pinBtn[2]));
}
43  Using Arduino / Project Guidance / Re: use arduino mega or not on: August 17, 2014, 08:45:04 pm
You can get 16 buttons with 8 pins using multiplexing.
Better yet, you can get 16 buttons with 5 pins using a 74HC4067.
With two 74HC4067 and a transistor to invert the CE line to one of them, you can get 32 buttons from 6 pins.
Although I've not tried it, it appears possible to get 64 buttons from 7 pins using 4 * 74HC4067 and half of a 74HC139. Much above that number of buttons might be problematical, due to having to cycle through all the possible addresses and the latency of that. It would depend on how fast you need the buttons to be read. For my 'fingerpoke' speed buttons, it wouldn't be much of a problem.
44  Using Arduino / Project Guidance / Re: Controlling multiple stepper motors with Arduino on: August 17, 2014, 07:40:06 pm
Any suggestions on where to start?
Start by writing a precise definition of your project and listing, in order, all the steps/stages that your finished project will go through. Once you've done that, you're more than half way there.
45  Using Arduino / Project Guidance / Re: ultrasonic ground speed detection on: August 17, 2014, 07:32:10 pm
Think ball-less mouse.
I don't know if IR will work at 50 Cms, though. I suspect that it will depend on the surface.
Pages: 1 2 [3] 4 5 ... 102