Pages: 1 [2] 3   Go Down
Author Topic: Beginner’s Blog  (Read 1972 times)
0 Members and 1 Guest are viewing this topic.
Canberra Australia
Offline Offline
God Member
*****
Karma: 8
Posts: 502
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes I realise that the formatting on that free website is not the best and at your suggestion I did investigate using some code tags to improve the readability. From what I have been able to find out I would need to pay for a site that allows the use of a plugin to do this and as this is basically being done as a learning exercise for me it isn't happening. There are quite a few restrictions with these free sites as you can imagine, but that is why they are free. I had the same problem when I tried to copy the code from the blog and paste it into the IDE. it seems that it is only copying one of the minus signs in this part of the code. If anyone can show me how I can improve the code formatting I would be gratefull but I spent hours last night here on the forum and googling all to no avail.
Code:
if(potReading > 8)
potReading –;

The code does compile but admittedly I do have the original in front of me so it is easy for me to spot where it is incorrectly being copied. I have attached the code that I used to control the counter with the pot if you are interesed Nick. Thanks again Pedro.

Code:

  //  7-Segment LED counter, multiplexing using 74HC595 8-bit shift register, increment counter zero to nine to zero via push button switch
  // Code mangled together from these sources - thanks fellas
  //  http://www.sweeting.org/mark/blog/2011/11/27/arduino-74hc595-shift-register-and-a-7-segment-led-display
  //  http://thecustomgeek.com/2011/06/29/multiplexing-for-a-7-year-old/
  //  http://nootropicdesign.com/projectlab/2009/10/25/led-clock/
  
  const int latchPin = 5;  // Pin connected to Pin 12 of 74HC595 (Latch)
  const int dataPin  = 6;  // Pin connected to Pin 14 of 74HC595 (Data)
  const int clockPin = 7;  // Pin connected to Pin 11 of 74HC595 (Clock)
  
  int counter = 0;          // initialise counter as zero
  int potReading =0;
  
  
  const byte numbers[10] =  // Describe each digit in terms of display segments  0, 1, 2, 3, 4, 5, 6, 7, 8, 9
  
  {
    B11111100,
    B01100000,
    B11011010,
    B11110010,
    B01100110,
    B10110110,
    B10111110,
    B11100000,
    B11111110,
    B11100110,
  };
  

  void setup()
  {
  
  
  
    pinMode(latchPin, OUTPUT);   // set SR pins to output
    pinMode(clockPin, OUTPUT);
    pinMode(dataPin, OUTPUT);
  
  }
  
  
  void loop()
  
  {
   potReading = analogRead (A0);
   potReading = map(potReading, 0, 1023, 0, 8);
    {
       if(potReading > 8)
         potReading --;
         show(numbers[potReading]);
        
    }
    
    {
       if(potReading < 0)
         potReading ++;
         show(numbers[potReading]);
        
    }
  }
    
  
  void show( byte number)
  {
    // Use a loop and a bitwise AND to move over each bit that makes up
    // the seven segment display (from left to right, A => G), and check
    // to see if it should be on or not
    for(int j = 0; j <= 7; j++)
    {
      byte toWrite = number & (B10000000 >> j);
  
      if(!toWrite) {
        continue;
      }  // If all bits are 0 then no point writing it to the shift register,so break out and move on to next segment.
  
      shiftIt(toWrite); // Otherwise shift it into the register
    }
  }
  

  void shiftIt (byte data)
  {
    digitalWrite(latchPin, LOW); // Set latchPin LOW while clocking these 8 bits in to the register
  
    for (int k=0; k <= 7; k++)
    {
      digitalWrite(clockPin, LOW); // clockPin LOW prior to sending a bit
  
      // Note that in our case, we need to set pinState to 0 (LOW) for
      // “On” as the 74HC595 is sinking current when using a common
      // anode display. If you want to use a common cathode display then
      // switch this around.
      if ( data & (1 << k) )
      {
        digitalWrite(dataPin, HIGH); // turn “On”
      }
      else
      {
        digitalWrite(dataPin, LOW); // turn “Off”
      }
      digitalWrite(clockPin, HIGH); // and clock the bit in
    }
    digitalWrite(clockPin, LOW);  //stop shifting out data
    digitalWrite(latchPin, HIGH); //set latchPin to high to lock and send data
  }


EDIT –
Just for interest potReading1 image is copied from the editing pane of the Wordpress blog and it has the correct two minus signs. However potReading2 image is copied from the blog page as it appears online and it only shows one minus sign. I assume it is those pesky HTML Gremlims at work again. Oh well, I found it interesting  smiley-grin


* potReading1.png (15.4 KB, 691x242 - viewed 15 times.)

* potReading2.png (15.43 KB, 703x245 - viewed 14 times.)
« Last Edit: October 10, 2013, 08:03:36 pm by Pedro147 » Logged


Canberra Australia
Offline Offline
God Member
*****
Karma: 8
Posts: 502
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I finally decided to lash out and get some hosting for a proper "big person's" website   smiley-lol  and have used the SyntaxHighlighter Evolved plugin with the Arduino brush extension. I think that it does a fabulous job of highlighting the code in an easy to read and colourful format. I just thought that I would show it here in case anyone else is interested in using this plugin on their Wordpress.com site as I know that I had some difficulty in tracking down what I actually needed to do. If anyone has any queries I am only too willing to offer any humble assistance that I can, Pedro.

Edit - Changed name of  SyntaxHighlighter  plugin to SyntaxHighlighter Evolved  plugin
« Last Edit: March 05, 2014, 10:27:45 pm by Pedro147 » Logged


nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8442
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

That syntax highlighter does a good job, does it only work with Wordpress or can I use it on my site?

BTW, what part of Canberra are you in?

______
Rob
« Last Edit: March 05, 2014, 04:24:48 am by Graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

Canberra Australia
Offline Offline
God Member
*****
Karma: 8
Posts: 502
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

As I am sure you are aware Rob I am very much on learner plates with all this website stuff, although I did manage to decimate a website tonight by improper use of a FTP program, but that’s another story. Wrecking stuff is a great way to learn.  smiley-evil
Have a look at this collection but they may only work on Wordpress, I’m not too sure.
http://alexgorbatchev.com/SyntaxHighlighter/manual/brushes/
Let me know how you go and if this is no good I’ll have a hunt through my browser history because I’m sure that there a bit more stuff I came across recently. I live in Narrabundah (not heights) but don’t hold that against me
Logged


nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8442
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks I'll have a look.

I'm sure Narrabundah will be an "in" suburb one day, I think even the Causeway must be looking up what with all that foreshore development close by. At least you have a house, I don't even have that smiley

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Canberra Australia
Offline Offline
God Member
*****
Karma: 8
Posts: 502
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes considering the ACT Govt was selling these prefabs in the early 80's for 10 - 15 k and now you cannot even get one for 450-500 k I'm pretty pleased  smiley-grin
Logged


nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8442
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yikes, we had 3 houses in Canberra, sold them when the market was depressed. Man I'd love to still own them now.

As you know Narrabundah was not considered the most salubrious part of town but the bottom line it that it's now an inner suburb and they ain't making any more of them.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Canberra Australia
Offline Offline
God Member
*****
Karma: 8
Posts: 502
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


 Narrabundah .....   now an inner suburb and they ain't making any more of them.


Exactly what I said to myself in 1994 when I had a choice of buying a modern house in Tuggeranong or an old prefab for $114,000. It was a no-brainer  smiley-cool
Logged


nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8442
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I tell you what, I wouldn't mind living in Canberra again and you must be keen to see the rest of the country, I'll swap you for my motorhome. It's a nice motorhome smiley I'll even pay for your HR licence if you haven't got one, and I can include enough oil for the first service. I can't be any fairer than that.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Canberra Australia
Offline Offline
God Member
*****
Karma: 8
Posts: 502
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'll speak to my financial advisor   smiley-lol
Logged


Offline Offline
Full Member
***
Karma: 3
Posts: 242
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

appreciate any suggestions or criticisms 

Suggestion
Ignore any comments on your style of formatting the code. (It takes way too much precious time of complainers to reformat it to their liking.)
Criticism
If  your "blog" is also intended to teach how to write code - use more comments and include ways to debug / troubleshoot the code.
Kudos / attaboys
You are the first person who posted initialization of pins in "for" loop instead of cut and paste lines of similar code over and over. But you did not do that when setting digits from 0 to 10, oh well.

I hope you continue in your endeavor, it is much more effective, and friendly than some of the one line snippets of would be ”teachers “ on this site.

Thanks for all of it.
I am sure it will be appreciated by many.
Vaclav

Logged

Canberra Australia
Offline Offline
God Member
*****
Karma: 8
Posts: 502
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for your comments Vaclav
Yes you are right peoples prefered style of code commenting is largely a personal preference and quite subjective. This being said I realise that some of the commenting that I did, was in some/many areas quite sparse or non existant. When I first had the urge to put up some kind of a website,these five different ways of driving 7 seg LED's were the only Arduino project area that I had any type of extended experience with. Sometimes the search for content is a cruel Mistress   smiley-grin
Thanks for taking the time to comment and I'll certainly take them on board,
Pedro
Logged


Tasmania - Australia
Offline Offline
Sr. Member
****
Karma: 10
Posts: 298
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Pedro,
Looking at your blog sites, I notice on your contact page you only have a google map of Canberra, no actual way to contact you, is this intentional?

The theme you are using tells me at the bottom 'Responsive Theme powered by WordPress', but when I view on a reduced screen size your top menu collapses as it should, but the drop down menu selection holds no menu items. 

On your other site 'pedrosdigitalsolutions.com' there appears to be a serious problem when you try to scroll down on this page http://pedrosdigitalsolutions.com/?page_id=152. Well, in my Chrome browser it does  smiley-eek

Keep having fun with the blog making  smiley
____
Paul
Logged


Canberra Australia
Offline Offline
God Member
*****
Karma: 8
Posts: 502
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Paul.
I am pretty new to all this website stuff and as soon as I signed up for hosting I started getting numerous e-mails telling me how good they were with WP websites and how they could build me one for $800 upwards. So consequently I removed contact details and changed my e-mail address at ICANN to a secondary e-mail account (spam filter )

As for the menu loss on resizing, it is a responsive theme but after I have been playing around with the underlying code the responsiveness "ain't so responsive anymore". But hey, I don't really expect much traffic as it's just a learning platform for me, but thanks for letting me know. That gives me something else to try and fix or totally butcher  smiley-cool

The hover test page is only a short section of text to check out the functionality of a hover text plugin.

Pedro
Logged


Canberra Australia
Offline Offline
God Member
*****
Karma: 8
Posts: 502
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Calling Rob "Graynomad" Grey.

You asked earlier on in this thread if you could use the SyntaxHighlighter with Arduino brush to post code on your non Wordpress site. I have moved away from WP and am now trying a bit of basic home coding on my learning platform site  http://www.pedroduino.com  After that shameless plug I will now get to the point - I saw these two articles that might be of use to you

http://www.electronics-micros.com/software-hardware/publishing-arduino-sketches-to-the-web/

https://someoneknows.wordpress.com/category/technology/arduino/

On my site I have used the copy as HTML function in the IDE  and it does a reasonable but basic job aside from the slack formatting "trick" of using  non breaking spaces to indent the code.  I am going to have a play around with the suggestions in these articles and I will report back if I have any success.

Pedro.
Logged


Pages: 1 [2] 3   Go Up
Jump to: