Showing posts with label Arduino. Show all posts
Showing posts with label Arduino. Show all posts

Tuesday, 12 July 2016

Software Engineering : Arduino Uno - Flashing Clock

What is this flashing clock?  Well, it's just an arduino uno, with three LED's, one each for the seconds, minutes and hours.  They don't show the time, they just flash as each period they're counting passes.

So, we're going to count the seconds and flash just the second LED.  Then each 60th flash, we reset the seconds counter, increment the minute counter and have the minute LED flash.  Ditto for the hour counter each 60th minute.

I've got the LED's VCC legs connected to digital pins 8, 9 and 10, with the other connected to the three grounds.  When I come to make this an actual board I can have a single ground pin being used up, rather then using all three on the board.

An important part of the code to focus on is how to turn on each light in turn...

If you want to turn on the second, the minute and the hour LED all at the same time, you could have some horrid "if" statement controlling them, but much more clean looking is this:

// Turn lights on
switch(CycleCount)
{
    case 2:  digitalWrite(HourPin, HIGH);
    case 1:  digitalWrite(MinutePin, HIGH);
    case 0:  digitalWrite(SecondPin, HIGH);
                break;
}

So, the count is reset to zero each cycle it is incremented if we add to the minutes, and incremented if we add to the hours.

The switch statement then drops through, notice that there are no "breaks" on the 2 and 1 (hours & minutes) cases.  So, if we have incremented the hour, we have a count of two and so we set the HourPin High, drop through to the MinutePin High and finally the Second Pin High before we break.

Likewise, if we only set the minutes this cycle, then the count will be one, so the switch statement will drop down to the Minute Pin high, skipping the Hour pin totally.

The effect of this is to seemingly instantly turn on all the LED's each cycle as they are needed together, there is no humanly noticeable staggering of the lights coming on, as one might get with an if statement, or once might get if one were to set the LED as we increment the values.  Doing Lights on when we increment actually clearly shows the LED's going on and off in a staggered pattern.

Our task after turning all of them on is to just wait a short time (100 milliseconds) and then turn them all off with another switch statement.  And with them all off again simply wait for the remainder of the second (i.e. 900 ms).


Keep this in mind as you read the following code:

// The pins
int SecondPin = 8;
int MinutePin = 9;
int HourPin = 10;

// The counts
int CycleCount = 0;
int SecondCount = 0;
int MinuteCount = 0;
int HourCount = 0;

void setup() 
{ 
  // Setup the pins
  pinMode (SecondPin, OUTPUT);
  pinMode (MinutePin, OUTPUT);
  pinMode (HourPin, OUTPUT);
}

void loop() 
{
  // Increment the counts
  CycleCount = 0;
  SecondCount = SecondCount + 1;
  if ( SecondCount > 59 )
  {
      SecondCount = 0;
      ++MinuteCount;
      ++CycleCount;

      if ( MinuteCount > 59 )
      {
        ++CycleCount;
        MinuteCount = 0;
        ++HourCount;

        if ( HourCount > 23 )
        {
          HourCount = 0;
        }
      }
  }

  // Turn lights on
  switch(CycleCount)
  {
    case 2:
      digitalWrite(HourPin, HIGH);
    case 1:
      digitalWrite(MinutePin, HIGH);
    case 0:
      digitalWrite(SecondPin, HIGH);
      break;
  }   

  // Light are on for 1/10 of a second
  delay(100);

  // Tuen lights off
  switch(CycleCount)
  {
    case 2:
      digitalWrite(HourPin, LOW);
    case 1:
      digitalWrite(MinutePin, LOW);
    case 0:
      digitalWrite(SecondPin, LOW);
      break;
  }   

  // Lights all off for 9/10 of a second
  delay (900);
}

If you found anything of use here, please return again, and don't forget to check out my other YouTube videos.

Monday, 13 June 2016

Electronics Tinkering : Project Plan #1

I've been wanting to tinker with some electronics for ages, and in my store, I have some Z80 CPU's and lots of TTL logic.  But before I dive into that, and since I'm totally untrained, I thought I'd have a play about with my soldering iron and see what I could mash together.

My plan therefore is to desolder a PS2 connector from one of the Socket 775 motherboards I killed, and to connect it to an arduino uno to read the pins.


Looking at this, I can mount the PS2 connector to a project board, solder on a set of headers and wire each pin to a known point on the header.

From there I can use jumper cables from my breadboard to bridge from the headers on the project board to the arduino.

At least, this is the theory.

The first thing I need to worry about is the clock, I have no idea what the clock rate is, if I need a crystal, or if a capacitor charging & discharging will do, or even if I can create the signal from a GPIO pin or PWM pin from the arduino... I'll have to look into that and let you all know.

My rough schematic is going to look like this on the project board:


The outer shell will be going to ground, and it has four feed to solder.  Then the four pins seem to point to clock, Ground, VCC and Data.  I'm not clear on which of the pins below become the sockets, so I'll have to insert something into the socket holes and check for continuity to the pins to know the order.

But each group of four will be soldered to a header, which I've marked read and blue.  One will be the upper set of ports, the other the lower.  I'm not going to distinguish keyboard/mouse because I just want a keyboard signal.

So, a bit of soldering with my new iron.  I'm going to have to de-solder with it too.

Below follows a list of the links I'm interested in looking through:

From the Wikipedia entry (yes I read Wikipedia) states:

"Communication is serialsynchronous and bidirectional.[1] The attached device generates the clock signal. The host controls communication using the clock line; when the host pulls the clock low, communication from the device is inhibited."


Sunday, 10 April 2016

Arc Welding Arduino Code

From my YouTube Video:



int ledPin = 13; // LED connected to digital pin 13

void setup()
{
pinMode(ledPin, OUTPUT);
}

void loop()
{
int i,count;
count=random(10,60);
for (i=0;i<count;i++)
{
digitalWrite(ledPin, HIGH); // set the LED on
delay(random(60));
digitalWrite(ledPin, LOW); // set the LED off
delay(random(200));
}
delay(random(800,2000)); // wait a random bit of time
}

Monday, 8 February 2016

Solder, Short Circuit and Surgery

I started the weekend finally trying to sort out a little board for ken to mount in his blacksmith shop, using three LEDs to give a flickering flame effect...


I can run nice pinned wires from the arduino to the header I've included here, and it allows me to change the intensity of things, the resistors help keep the different channels dimmer for the LED's and so the light is not over powering.

However, whilst working on this board I found the soldering iron was being a real pig, it took forever to get to temperature, solder would not really melt - despite being fine previously - and then I found the handle to be very warm, and the solder would instantly vapouriser if touched on the iron's shroud.

So, I powered it off, let it cool, checked the tip... Nothing seemingly wrong, I plug it all back in, and as I flick the power switch the whole house goes dark.. Yep, I tripped the house's main fuse.. WHOOPS.

But, this freaking iron, I think it's dead.... I may have to start researching and flutter my eye lids at the wife to let me go buy a proper nice, temperature controlled soldering station.

And now finally, I have my date for my ankle surgery, yes they need to go back into the right ankle joint and have a tinker around, I went for my pre-op on Friday, and they operate in a fortnight... However, right now I have an appointment with a respiratory doctor and a stinking cold... Gah.

Gaming wise, I've been playing lots of World of Warships, but I'm also still playing Crown of the Gods, a clone of Lord of Ultima.


And project-wise, for code at least, I've started working on my own SDL2 based, XML driven 2D UI, for adding overlays or creating tools in C++, this is going to be useful for high-speed customisable and internationalization tasks I need perform; both at home and at work.

Friday, 5 February 2016

DCC Train Test Bed

I've spent some time this evening actually getting around to setting up a length of 00 Gauge railway track, in order to test my DCC base station and sniffer builds.

I've lots of electronics lying around and to be honest I need to knuckle down and play about with them more.


You can see I have a reference DCC station here, a Gaugemaster unit, I'd much prefer to have the actual ESU Ecos system on the real-layout, but Ken wouldn't let me bring it home... not least as it'd leave him with nothing to play with.

Anyway, you can see this is actually longer than my desks, so it goes way off into the ether, and I've propped the left end up (just to stop it sagging under it's own weight) with a cardboard tube I had lying around.

Then, in the center above the mini screw drivers you can see the pile of Arduino Uno boards I have, and then the mess of electronics in various re-purposed glass jars.

And my quality £3 volt meter just poking into view... Hey, hey, it's not a Fluke, but it does the job for now.

Friday, 8 January 2016

Happy New Year 2016

So it's eight days into the New Year, and I haven't posted yet!... Oh well, here I am now...

I've nothing to report yet, I'm busy building some kit



Yes, that is a Chinese Arduino Uno clone... Costing £2.39... And it works a treat!


And I've been playing WarThunder....

And I've been cooking home made pizza....


My stories of what happened over Christmas, I'll have to get back to you later about.