Go Down

Topic: Beginner’s Blog (Read 4554 times) previous topic - next topic

Pedro147

#15
Oct 11, 2013, 02:28 am Last Edit: Oct 11, 2013, 03:03 am by Pedro147 Reason: 1
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: [Select]

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: [Select]


 //  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  :D
http://www.pedroduino.com

Pedro147

#16
Mar 05, 2014, 04:53 am Last Edit: Nov 30, 2014, 01:47 am by Pedro147
I finally decided to lash out and get some hosting for a proper "big person's" website   XD  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-1 - Changed name of  SyntaxHighlighter  plugin to SyntaxHighlighter Evolved  plugin

Edit-2 - Code highlighting now done by Javascript written by Jason Knight available at reply #11 http://www.webdeveloper.com/forum/showthread.php?298017-Javascript-to-format-Arduino-code&p=1347149&highlight=#post1347149
http://www.pedroduino.com

Graynomad

#17
Mar 05, 2014, 09:35 am Last Edit: Mar 05, 2014, 10:24 am by Graynomad Reason: 1
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
Rob Gray aka the GRAYnomad www.robgray.com

Pedro147

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.  ]:)
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
http://www.pedroduino.com

Graynomad

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 :)

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Pedro147

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  :D
http://www.pedroduino.com

Graynomad

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
Rob Gray aka the GRAYnomad www.robgray.com

Pedro147



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  8)
http://www.pedroduino.com

Graynomad

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 :) 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
Rob Gray aka the GRAYnomad www.robgray.com

Pedro147

I'll speak to my financial advisor   XD
http://www.pedroduino.com

Vaclav


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


Pedro147

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   :D
Thanks for taking the time to comment and I'll certainly take them on board,
Pedro
http://www.pedroduino.com

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  :)
____
Paul

Pedro147

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  8)

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

Pedro
http://www.pedroduino.com

Pedro147

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.
http://www.pedroduino.com

Go Up