Show Posts
Pages: [1] 2 3
1  Products / Arduino Due / Re: Composite Video Generating on: December 18, 2013, 10:55:25 pm
Hi There.
I just got myself an Arduino due today and thought what better way to try it out then with your cool graphics smiley
Do you have a library ? or any code I can run. Possibly a circuit diagram if it's not to much trouble of course.
You did a fantastic job on your project, well done
Thanks
BlackSnake
2  Using Arduino / Programming Questions / Works there but not here :( Anyone see why ???? on: September 16, 2013, 10:34:04 pm
Hi Guy's
I am working on an adjustment routine and had it working in one sketch but it won't allow me to change the settings in the other sketch.
This code is the working sketch
Code:
void loop() 
{

  MainVolts = analogRead(A0);
  AuxVolts = analogRead(A1);
  long total1 =  cs_7_8.capacitiveSensor(30); // Left
  long total2 =  cs_7_9.capacitiveSensor(30); // Middle
  long total3 =  cs_7_10.capacitiveSensor(30); // Right

  if(total1 > 120 && total3 > 120 && screen == 0)
  {
    set = true;
    //         0123456789012345
    lcd.setCursor(0,0);
    lcd.print("ADJUSTMENT  MODE");
    lcd.setCursor(0,1);
    lcd.print("< =TIME > =VOLTS");
    delay(2000); // change to 1000 for board version
    // Mode = 6, Above last number (This needs to become part of the main loop
    lcd.setCursor(0,0);
    lcd.print("LINK VOLTS >");
    lcd.setCursor(12,0);
    lcd.print(linkVoltSet,1);
    lcd.setCursor(0,1);
    lcd.print("LINK TIME  <");
    lcd.setCursor(12,1);
    lcd.print(time);
   screen = 1;
  }
 
  // This next GIANT section for adjustment needs to be kicked out of the loop
 
  //*************************** SCREEN ONE *****************************************
 if(set == true && screen == 1)// && Mode == 6)
  {
    if(total1 > 120)// left button does volts
    {
      linkVoltSet = linkVoltSet + .1;
      lcd.setCursor(12,0);
      lcd.print(linkVoltSet);
      if(linkVoltSet >= 14.4)
      {
        linkVoltSet = 12.4;
      }
      delay(50); // stops multiple preses
    }
    // maybe wright this to eeprom ????
    if(total3 > 120)
    {
      time = time + 5;
      lcd.setCursor(12,1);
      lcd.print("   ");
      lcd.setCursor(12,1);
      lcd.print(time);
      delay(100);
     if(time >= 120)
    {
      time = 0;
    }
    }
   
    if (total2 > 100)
    {
      // Step to next point in menu
      screen = 2;
      set = false;
      //set = true;
    }
   
   
  } 
   
// ******************************** SCREEN TWO *************************************   
    if(screen == 2 && set == false)
    {
      lcd.print(" ha ha ");
      if(total3 > 150)
      {
        unLinkVoltSet = unLinkVoltSet + .1;
        lcd.setCursor(0,0);
        lcd.print("SCREEN TWO");
        lcd.setCursor(12,0);
        lcd.print(unLinkVoltSet,1);
        if(unLinkVoltSet >= 13.8)
        {
          unLinkVoltSet = 12.0;
        }
        delay(50);
      }
    }


This is the code that on the second settings (Unlink V & Unlink T) I can't change the numbers, it's like the capsense buttons are not being seen. I have looked over it many times and 25 hours later I'm asking for help smiley
Please let me know if you can see why this code does not work like the first one ??????
Thanks
Code:
void loop() 
{

  MainVolts = analogRead(A0);
  AuxVolts = analogRead(A1);
  long total1 =  cs_7_8.capacitiveSensor(30); // Left
  long total2 =  cs_7_9.capacitiveSensor(30); // Middle
  long total3 =  cs_7_10.capacitiveSensor(30); // Right


  // ************************** ADJUSTMENT MODE ******************************
  // ******************** PAGE No 1 ******************************************
  if(total1 > 120 && total3 > 120 && screen == 0)
  {
    set = true;
    //         0123456789012345
    lcd.setCursor(0,0);
    lcd.print("ADJUSTMENT  MODE");
    lcd.setCursor(0,1);
    lcd.print("< =TIME > =VOLTS");
    delay(2000); // change to 1000 for board version
    lcd.setCursor(0,0);
    lcd.print(" MAIN SOLENOID ");
    lcd.setCursor(0,1);
    lcd.print("     LINK      ");
    delay(2000); // change to 1000 for board version
    lcd.setCursor(0,0);
    lcd.print("LINK VOLTS >");
    lcd.setCursor(12,0);
    lcd.print(linkVoltSet,1);
    lcd.setCursor(0,1);
    lcd.print("LINK TIME  <");
    lcd.setCursor(12,1);
    lcd.print(time);
    screen = 1;
  }
   
 

  // This next GIANT section for adjustment needs to be kicked out of the loop

  //*************************** SCREEN TWO *****************************************
  if(set == true && screen == 1)// && Mode == 6)
  {
    if(total1 > 120)// left button does volts
    {
      linkVoltSet = linkVoltSet + .1;
      lcd.setCursor(12,0);
      lcd.print(linkVoltSet);
      if(linkVoltSet >= 14.4)
      {
        linkVoltSet = 12.4;
      }
      delay(50); // stops multiple preses
    }
    // maybe wright this to eeprom ????
    if(total3 > 120)
    {
      time = time + 5;
      lcd.setCursor(12,1);
      lcd.print("   ");
      lcd.setCursor(12,1);
      lcd.print(time);
      delay(100);
      if(time >= 120)
      {
        time = 0;
      }
    }

    if (total2 > 100)
    {
      // Step to next point in menu
      screen = 2;
      set = false;
      userLinkV = linkVoltSet; // Store the user settings.
      userLinkT = time; // Store the Time for Linking Main Solenoid

    }


  }

  // ******************************** SCREEN TWO *************************************   
  if(set == false && screen == 2)
  {

    //         0123456789012345
    lcd.setCursor(0,0);
    lcd.print(" MAIN SOLENOID  ");
    lcd.setCursor(0,1);
    lcd.print("     UNLINK     ");
    delay(2000); // change to 1000 for board version
    lcd.setCursor(0,0);
    lcd.print("UNLINK V  >");
    lcd.setCursor(12,0);
    lcd.print(unlinkVoltSet,1);
    lcd.setCursor(0,1);
    lcd.print("UNLINK T  <");
    lcd.setCursor(12,1);
    lcd.print(time);
    screen = 3;
    set = true;
 
  }
 
 
  if(set == true && screen == 3)
  {
    lcd.setCursor(0,0);
    if(total1 > 120)// left button does volts
    {
      unlinkVoltSet = unlinkVoltSet + .1;
      lcd.setCursor(12,0);
      lcd.print(unlinkVoltSet);
      if(unlinkVoltSet >= 14.4)
      {
        unlinkVoltSet = 12.4;
      }
      delay(50); // stops multiple preses
    }
    // maybe wright this to eeprom ????
    if(total3 > 120)
    {
      time = time + 5;
      lcd.setCursor(12,1);
      lcd.print("   ");
      lcd.setCursor(12,1);
      lcd.print(time);
      delay(100);
      if(time >= 120)
      {
        time = 0;
      }
    }

    if (total2 > 100)
    {
      // Step to next point in menu
      screen = 4;
      set = false;
      userUnlinkV = unlinkVoltSet; // Store the user settings.
      userUnlinkT = time; // Store the Time for Linking Main Solenoid

    }




  }
}
smiley-mad smiley-mad smiley-mad smiley-mad smiley-mad
3  Using Arduino / Programming Questions / Turning 6 inputs into a Binary Number on: April 30, 2013, 12:26:50 am
Hi All,
I have been trying to find out how I can read 6 digital inputs and turn the results into one Binary number ie 100101 so I can change settings depending on which switches are on or off.
Does anyone know where I can find this information or have any code snippets that would help ?
Thanks
4  Using Arduino / Programming Questions / Percentage Modulo ? on: April 11, 2013, 08:47:40 pm
Hi Guy's n Girls, How are we all today.

If I want to take an integer from another integer and come up with a percentage based on the difference between the 2 numbers,
Is modulo the right way to go about it or does someone have a better way or code where they have done similar ?
Thanks
5  Using Arduino / Programming Questions / Accuracy on AnalogRead using Internal reference on: April 01, 2013, 10:10:30 pm
Hi all,

I am having difficulty with accuracy and have come up with the idea of measuring a known voltage and then finding out what multiply ratio is required. I would then like to store this in flash as a cal constant.
Then I would call this number as my multiply ratio.
I many lumps from banging my head against a wall I thought I would get help.

Does anyone have any tips or code on doing this ?

Code:
MainInput = analogRead(0); // Read Analog input 0, Main battery
  MainVolts = (MainInput * 17.7) / 1024; // convert raw data to voltage
6  Using Arduino / Programming Questions / Re: I want to have a pin on for 10 seconds before it is considered on on: April 01, 2013, 10:04:05 pm
Hi,
I had a similar issue and was pointed to the Elapsed timing library (Much easier then millis)
Example

If (pin == HIGH)
{
   t1.reset();
}

if(t1.intervalMs() > 10000)
{
do something;
}

Nick Gammon has created this library and you can check out his site at nickgammon.com (hard to site find stuff thou)
I used it to check when a battery went above a certain level it began a 30sec timer at the end of the time it checks that it is still above the voltage and acts accordingly. you need to add variable to change states, below is the code I used

#include <Elapsed.h> // Library for Timers

 static Elapsed t1, t2, t3, t4, t5, t6, t7; // Timers for the many timing demands ( You only need one )

void loop() {

if (AuxVolts >= 13 && !Press1 && Act1 != HIGH)
  {
   Act1 = HIGH;
   Act = LOW;
   Press1 = true;
   t7.reset();
  }
 
 if (Press1 && t7.intervalMs() > 7500 && AuxVolts >= 13)
  {
    Press1 = false;
    digitalWrite(AuxRelay, HIGH);
  }
  else if (AuxVolts <= 13)
  {
    t7.reset();
  }

Hope this helps !
7  Using Arduino / Programming Questions / Re: how to get 4 digit decimal no. on: March 08, 2013, 10:36:11 pm
With a print function you can define how many 0's you want after the decimal point
ie print(a0,2); will print to 2 decimal places.
I use this for voltages myself but I have found sometimes if the voltage is under ten and using an LCD 2 line display I will get 3 decimal places instead of 2.
Not sure if this problem occurs on serial monitor.
Hope this helps
8  Using Arduino / Programming Questions / Capacitive Sense - Quick Question on: March 08, 2013, 10:22:39 pm
Hi Guys,

I am creating a matrix with 12 cap sense buttons.

Do I need a send wire for each port or can I just use 1 for all the digital inputs, I am using capacitiveSense04 library ?

Thanks
9  Using Arduino / Programming Questions / Elapsed Timing Library for 1.02 on: November 24, 2012, 07:23:56 pm
Hi all,

I have the Elapsed Timer library for Arduino 022 and my program works great.
However it will not work in version 1.02, I get the following error messages.
Can anyone point me to the updated library or a fix ?

C:\Users\Denis\arduino-1.0.2\libraries\Elapsed\Elapsed.cpp: In member function 'void Elapsed::reset()':
C:\Users\Denis\arduino-1.0.2\libraries\Elapsed\Elapsed.cpp:52: error: 'micros' was not declared in this scope
C:\Users\Denis\arduino-1.0.2\libraries\Elapsed\Elapsed.cpp:53: error: 'millis' was not declared in this scope
C:\Users\Denis\arduino-1.0.2\libraries\Elapsed\Elapsed.cpp: In member function 'long unsigned int Elapsed::intervalMs()':
C:\Users\Denis\arduino-1.0.2\libraries\Elapsed\Elapsed.cpp:59: error: 'millis' was not declared in this scope
C:\Users\Denis\arduino-1.0.2\libraries\Elapsed\Elapsed.cpp: In member function 'long unsigned int Elapsed::intervalUs()':
C:\Users\Denis\arduino-1.0.2\libraries\Elapsed\Elapsed.cpp:65: error: 'micros' was not declared in this scope
10  Using Arduino / Programming Questions / Re: Run and repeat function until press next pushbutton on: November 24, 2012, 07:20:52 pm
I did what you want but with one button by using a variable to store the counts as previously suggested.

int Mode = 0;
Mode = (digitalRead, button);
if(Mode == HIGH)
{
    Mode ++;
}
if(Mode == 0)
{
   do something;
}
// repeat for each function
then you will need to reset your counter
if(Mode > 2)
{
  Mode = 0;
}

11  Using Arduino / Programming Questions / Re: Taking the next step ! on: November 21, 2012, 05:17:51 am
Here is my code now, if you can see any problems or have any suggestions, feel free ?

Code:
#include <LiquidCrystal.h> // Library for the Liquid Crystal Display
#include <CapacitiveSensor.h> // Library for the Cap Sense switch.

// Constants to assign digital I/O's, these will not change.
const int Relay = 8; // Relay on digital pin 8.
const int AuxRelay = 7; // Load relay on digital pin 7.
//const int Ignition = 9; // Digital input to sense when the ignition is turn on or off.
const int BackLight = 6; // Digital OUTPUT for the Pulse width modulation to control the backlight.

// Variables to store data in.
int MainVolts = 0; // Stores the DAC value from the analog input connected to the Main Battery.
int AuxVolts = 0; // Stores the DAC value from the analog input conneted to the Aux Battery.
int LDR = 0; // Stores the DAC value from the analog input connected to the Light dependent resistor.
int LastState = LOW; // Stores the previous state of the ignition, Starts in the ignition OFF position.

// Define the pins the liquid crystal display is connected too.
LiquidCrystal lcd (12, 11, 5, 4, 3, 2);

// Setup - Define pins, intiallise display, any code that you want run only once.
// Analog inputs & PWM (analog outputs) do not need to be defined.
void setup ()
{
  lcd.begin(16,2); // intiallises the LCD display and defines the size (16 Characters, 2 Lines).
  pinMode(Relay, OUTPUT); // Sets the Relay on Pin 8 to an OUTPUT.
  pinMode(AuxRelay, OUTPUT); // Sets the AuxRelay on Pin 7 to an OUTPUT.
  //Serial.begin(9600); // Intialilises the Serial display for testing purposes.
}


// Main Program - This will run thru continously until power is disconnected or reset button is pressed. 
void loop() 
{
  //int result = analogRead(A4); // Power
  //int result1 = analogRead(A5); // LDR
  // I WONDER HOW TO PUT SPACES BETWEEN MY RESULTS, NEED TO FIND THAT OUT
  //Serial.print(result); // Power in DAC Counts
  //Serial.println(result1); // LDR in DAC Counts
  TurnMeOn(); // Meant to run code inside the function (TurnMeOn).
  delay(50); // Delay for LCD display   
}


void TurnMeOn(){

  // Check the state of the Ignition and turn off backlight if off or PWM backlight and display company details.
  int Power = analogRead(A4); // Check the state of the ignition pin and store the result in "power".


  // Ignition has just been switched ON from the OFF state, We want to throw in a little advertising. 
  if ( Power > 700 && LastState == LOW )
  {
    analogWrite(BackLight, 200); // Sets the Backlight to 3/4 brightness for logo only.
    lcd.clear(); // Clears the LCD display.
    lcd.print(" BLACKSNAKE SYS "); // Prints whats in the brackets on the LCD display.
    // Spaces  1234567890123456 , this is just to make sure we are using the correct number of characters available on the LCD.
    lcd.setCursor(0,1); // Sets the cursor the the first position on line 2. (Character, Line (16,2)).
    lcd.print("DBC MARK 4, Ver1"); // prints to LCD.
    LastState = HIGH; // Stops this from occuring every loop.
    delay(2000); // Delay's for 2 seconds whilst company logo is being displayed.
    lcd.clear(); // Clears the display.
  }
  // Igniton is on - Control intensity of Backlight by reading the LDR and PWMing the Backlight.   
  if (Power > 700 && LastState == HIGH) // Checks to see if the Ignition is on by looking for more then 700 DAC counts

  {                                   // Also checks Last State is HIGH (It has already displayed company logo.

    LDR = analogRead(A5); // reads the DAC Counts from Analog 5 and stores the result in LDR.
    analogWrite(BackLight, LDR / 2); // PWM's the backlight between 0 & 255.
    lcd.setCursor(0,0); // Sets the Cursor to Position 1, Line 1.
    lcd.print("power off"); // Prints to LCD
  }
  // If the ignition is switched off we will turn the backlight off to reduce theft factor.   
  if ( Power  < 500 ) // Checks that the ignition is below 500 DAC counts.
  {
    analogWrite(BackLight, 0); // Sets the Backlight PWM to 0 (OFF)
    LastState = LOW; // Sets state to LOW so logo is written when ignition is turned back on
  }

}
12  Using Arduino / Programming Questions / Re: Taking the next step ! on: November 21, 2012, 05:12:04 am
I had to close off each if statement of course but now it works the same as it did in the loop..
Whoo Hooo I have finally written a successful function outside of the loop.
Your patience and advice is VERY appreciated Cyber

13  Using Arduino / Programming Questions / Re: Taking the next step ! on: November 21, 2012, 05:06:29 am
Thanks Cyber, I change it around with the second statement and it works.. Whoo Hooo.
 smiley-wink
14  Using Arduino / Programming Questions / Re: Taking the next step ! on: November 21, 2012, 04:40:57 am
Thanks Nick !
Great to see your always so helpful and understand that not everyone is up to your standards...
FYI - I wrote it to work and in the void loop() it does. Then I just moved everything outside the loop to try to create it as a sub routine.
I realise the serial does not work in the posted code and was only using it when it was in the loop.
 Awol, Here is the full code, If you want I can send you the earlier full working version that has some of Nicks input (It's what I am trying to re-write as it was my first real program.
Code:
/* DUAL BATTERY CONTROLLER - MARK 4. Created by Chris Cobley on 20th November, 2012.
   Essentially the same functions of the Mark 3 software but it's a full re-write using
   all the new found programming skills. WISH ME LUCK !
   This version eliminates alot of electronic components and uses the cap sense library
   PWM to control the backlight.
*/

#include <LiquidCrystal.h> // Library for the Liquid Crystal Display
#include <CapacitiveSensor.h> // Library for the Cap Sense switch.

// Constants to assign digital I/O's, these will not change.
const int Relay = 8; // Relay on digital pin 8.
const int AuxRelay = 7; // Load relay on digital pin 7.
//const int Ignition = 9; // Digital input to sense when the ignition is turn on or off.
const int BackLight = 6; // Digital OUTPUT for the Pulse width modulation to control the backlight.

// Variables to store data in.
int MainVolts = 0; // Stores the DAC value from the analog input connected to the Main Battery.
int AuxVolts = 0; // Stores the DAC value from the analog input conneted to the Aux Battery.
int LDR = 0; // Stores the DAC value from the analog input connected to the Light dependent resistor.
int LastState = LOW; // Stores the previous state of the ignition, Starts in the ignition OFF position.

// Define the pins the liquid crystal display is connected too.
LiquidCrystal lcd (12, 11, 5, 4, 3, 2);

// Setup - Define pins, intiallise display, any code that you want run only once.
// Analog inputs & PWM (analog outputs) do not need to be defined.
void setup ()
  {
    lcd.begin(16,2); // intiallises the LCD display and defines the size (16 Characters, 2 Lines).
    pinMode(Relay, OUTPUT); // Sets the Relay on Pin 8 to an OUTPUT.
    pinMode(AuxRelay, OUTPUT); // Sets the AuxRelay on Pin 7 to an OUTPUT.
    Serial.begin(9600); // Intialilises the Serial display for testing purposes.
  }
  
  
// Main Program - This will run thru continously until power is disconnected or reset button is pressed.  
void loop()  
  {
    int result = analogRead(A4); // Power
    int result1 = analogRead(A5); // LDR
    // I WONDER HOW TO PUT SPACES BETWEEN MY RESULTS, NEED TO FIND THAT OUT
   Serial.print(result); // Power in DAC Counts
   Serial.println(result1); // LDR in DAC Counts
   TurnMeOn(); // Meant to run code inside the function (TurnMeOn).
   delay(50); // Delay for LCD display  
  }


void TurnMeOn(){

// Check the state of the Ignition and turn off backlight if off or PWM backlight and display company details.
int Power = analogRead(A4); // Check the state of the ignition pin and store the result in "power".
// Igniton is on - Control intensity of Backlight by reading the LDR and PWMing the Backlight.
 if (Power > 700 && LastState == HIGH) // Checks to see if the Ignition is on by looking for more then 700 DAC counts
    
    {                                   // Also checks Last State is HIGH (It has already displayed company logo.
    
      LDR = analogRead(A5); // reads the DAC Counts from Analog 5 and stores the result in LDR.
      analogWrite(BackLight, LDR / 2); // PWM's the backlight between 0 & 255.
      lcd.setCursor(0,0); // Sets the Cursor to Position 1, Line 1.
      lcd.print("power off"); // Prints to LCD
    
    
// Ignition has just been switched ON from the OFF state, We want to throw in a little advertising.  
  if ( Power > 700 && LastState == LOW )
    {
      analogWrite(BackLight, 200); // Sets the Backlight to 3/4 brightness for logo only.
      lcd.clear(); // Clears the LCD display.
      lcd.print(" BLACKSNAKE SYS "); // Prints whats in the brackets on the LCD display.
      // Spaces  1234567890123456 , this is just to make sure we are using the correct number of characters available on the LCD.
      lcd.setCursor(0,1); // Sets the cursor the the first position on line 2. (Character, Line (16,2)).
      lcd.print("DBC MARK 4, Ver1"); // prints to LCD.
      LastState = HIGH; // Stops this from occuring every loop.
      delay(2000); // Delay's for 2 seconds whilst company logo is being displayed.
      lcd.clear(); // Clears the display.
    

// If the ignition is switched off we will turn the backlight off to reduce theft factor.  
  if ( Power  < 500 ) // Checks that the ignition is below 500 DAC counts.
    {
      analogWrite(BackLight, 0); // Sets the Backlight PWM to 0 (OFF)
      LastState = LOW; // Sets state to LOW so logo is written when ignition is turned back on
    
}
}
}
}

I'm thinking I need to send the analog results to the function ( kinda like void TurnMeOn(int power, int LDR); )
not sure what exactly I need to do. This is what I am thinking, let know if I am on the right track.

void loop ()
{
   int a = analogRead(A4);
   int b = analogRead(A5);
   TurnMeOn(int Power, int LDR);

Will a be Power & b be LDR ?
15  Using Arduino / Programming Questions / Re: Taking the next step ! on: November 21, 2012, 03:24:52 am
So should i expect a result from this function ?
This is where I have trouble working out what can and can't be done in a function.
I want it to do whats in the function and then return to the main program, Is the code correct ?
I added the () at the end of the function call but it made no difference.
I get no display, no backlight, no nothing !
P.S. The ugly code is only cause I was trying different things, I would normally put them on separate lines smiley
Pages: [1] 2 3