Go Down

Topic: Apprentice coder (Read 5 times) previous topic - next topic

lloyddean

#70
Nov 03, 2012, 03:08 am Last Edit: Nov 03, 2012, 03:12 am by lloyddean Reason: 1
More accurate would be - parameter name suggestive of implied use.

See <http://www.cplusplus.com/doc/tutorial/variables/>
<http://www.cplusplus.com/doc/tutorial/constants/>
<http://www.cplusplus.com/doc/tutorial/operators/>

Pedro147

#71
Nov 03, 2012, 03:52 am Last Edit: Nov 03, 2012, 03:56 am by Pedro147 Reason: 1
lloyddean I knew exactly what you mean't. I try not to be too pedantic 8) Thanks again, I'm playing around with inserting the digitalWrite ! digitalRead ( syntax ? ) into my code in progress, just need to nut out the flash_count aspect, although I will definitely be studying the cplusplus tutorials as I know my understanding needs vast amounts of improvement.

lloyddean

Here are the declaration (as opposed to definitions) of some subroutines, functions, that you are more familiar with -

Code: [Select]

void pinMode(uint8_t pin, uint8_t mode);
uint8_t getPinMode(uint8_t pin);
void digitalWrite(uint8_t pin, uint8_t val);
int digitalRead(uint8_t pin);


Pedro147

#73
Nov 03, 2012, 09:02 am Last Edit: Nov 03, 2012, 12:55 pm by Pedro147 Reason: 1
Thanks for that and I am determined to get a firmer grasp of this.

Pedro147

I have been working on coding a 7 seg LED display to display from zero through to nine in a loop. As I am awaiting delivery of these displays, I am experimenting with using eight LED's in a row to display binary patterns approximating what will be required to display zero through nine when the 7 seg's arrive. The code that I am using is heavily based on Grumpy Mike's tutorial at  http://www.thebox.myzen.co.uk/Tutorial/Arrays.html
Code: [Select]

// Thanks to Grumpy Mike  http://www.thebox.myzen.co.uk/Tutorial/Arrays.html

int pins [] = { 2, 3, 4, 5, 6, 7, 8, 9 };
int digit[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
int timer = 1000;
char eightCode[] = { B01111110, B00110000, B01101101, B01111001, B00110011, B01011011, B01011111, B01110000 };
// Array element #       0          1          2          3          4          5          6          7


void setup()
{
  for(int i = 0; i < 8; i++)         // set digital pins as OUTPUTS
    pinMode(pins[i], OUTPUT);
}

void loop()
{

  for(int j = 0; j < 8; j++)        // loop through digit array
  {
    display8(digit[j]);             // function to display elements of eightCode array
    delay(timer);                   // delay between displaying of eightCode elements

  }
}





void display8(int num)
{
  int mask = 1;
  for(int i = 0; i < 8; i++)
  {
    if((mask & eightCode[num]) == 0)
      digitalWrite(pins[i], LOW);
    else digitalWrite(pins[i], HIGH);
    mask = mask << 1;
  }
}


I was just hoping that someone could have a look at the code and point out any glaring mistakes or improvements I could implement. It seems to be doing what I hoped it would do so I suppose that is a good sign.   8) Thanks Pedro.


Go Up