2

Im involved in a project that uses an arduino as a test device for an electrical panel that goes like this.

User will input "type" number through a keypad and based on the input, the device should be able to reassign pin modes.

everything else seems to be working flawlessly for me except that Ive come to the point where there are too many possible types involved. At the moment, I am able to do the process required using a switch-case statement since for a prototype, i decided to only incorporate 10 types.

The main goal would be that the device should be capable of distinguishing multiple(1-100) types that have subtypes(100+). so in total there could be hundreds of items that needs to be stored within the device and thats why i decided to use an SD card to hold the data.

I am not new to programming so i can easily grasp concepts but my biggest problem right now is that I dont know the best way to implement this process.

What Im asking for is just some sort of a process flow to implement the query on a file on an sd card and return values(pin numbers that needs to be assigned in order for the device to allow inputs on some pins and send outputs on some.) no need for specific lines but an example for a query and return value would be very much appreciated. Thanks!

PS. the device will not be connected to any other another platform.

user2747534
  • 31
  • 1
  • 4

2 Answers2

0

You can store some data on the SD card (http://arduino.cc/en/Reference/SD) but it won't be compile-able code, so you'd have to store some data structures in ASCII.

Another suggestion is to use a different model Arduino such as the Arduino Due, it has a whopping 512KB of flash memory for code (normal Arduino has 32KB).

This doesn't fix your root problem, which is large switch statement. Have a look at these for ideas:

Community
  • 1
  • 1
sinaptik
  • 331
  • 5
  • 15
  • 1
    Thanks for the suggestion however, i dont believe hard coding my database within the arduino itself is a good idea. Im trying to interface the arduino with an sd card reader that would contain the database. what would be the most efficient way of doing this? I was planning on just comparing the 1st string in every line of the file to the user input.. – user2747534 Sep 06 '13 at 20:52
0

I think you can start with implementing look-table kind of structure, using mix of structure and array. Since I don't know the format of input which user will be entering Let look for simple case wherein both type and sub-type are number between 1 to 100. In this case simple 2D array can be used, with each element of array corresponding to pin-out mapping. Now this pinout mapping can be bit map. Since I don't know much information about what kind of mapping you are doing. for example lets say you have 8 pins with each can be either in or out, for this you can use 8bits, each bit number itself corresponding to pin-number and bit value corresponding to in or out. If you have more than two state then you can use two bits instead of one to get 4 four possible value.

However if user input is in form of string. In that case you will need to use array of structure to create map like data-structure and search through it for particular pin-out.

    struct first_level_map
    {
      string type;
      uint8_t firs_level_id;
    }

    struct second_level_map
    {
      string subtype;
      uint8_t pin_out;
    }

    struct first_level_map type_array[100];
    struct second_level_map subtype_array[100];

    struct first_second_map
    {
      uint8_t second_level_id;
      struct second_level_map subtype_array[100];
    }
   struct first_second_map first_second_map_array[100];

Type user input--->Get first_level_id ----> Index first_second_map_array----> Get second_level_id-->From Subtype--->Get pin-out

praks411
  • 1,972
  • 16
  • 23
  • The Bit Masking idea seems simple enough to implement. Thats actually a good idea! would it be a problem if i had 24 bits in the array? user inputs are in string since im using a keypad for user input and inputs may have "."(period) in it. I was planning on reading a file from sd card and run a query for a specific string eg. Type 12.1 and save the following parameters into a variables to be used in the code. I have a vague idea on how to implement this however my only concern is that the type numbers can reach up to 200 elements. is that gonna be a problem as far as the arduino is concerned? – user2747534 Sep 06 '13 at 20:45
  • For bit mask for 24bits you can use unsigned int 32 bits, if this is not available then use two uint16. 200 can be easily accommodated in uint8_t so this won't be problem. Also you can move this array into code space if you are not going to update else you can go ahead with SD card. – praks411 Sep 06 '13 at 23:01