Show Posts
Pages: 1 ... 53 54 [55] 56 57 ... 242
811  Using Arduino / Project Guidance / Re: Button Help, Up, Down, Select on: March 23, 2014, 11:54:35 pm
So something like this?
Code:
#include <LiquidCrystal.h>

LiquidCrystal lcd(7,8,9,10,11,12);


#define factor 1000
//Set buttons pin numbers
const byte incrementButton = 5;
const byte decrementButton = 6;
const byte SelectButton = 3;

//Global variables
boolean incrementState = 0; //variable that will read the increment button (either HIGH or LOW)
boolean decrementState = 0; //variable that will read the decrement button (either HIGH or LOW)
int counter = 0; //variable that will store the count
boolean lastIncrementState = 0;
boolean lastDecrementState = 0;
boolean selectState = 0;
boolean lastSelectState = false, State = false, ON = true;
int led = 13;
unsigned long Ontime = 0, Offtime = 0;
byte TimeOn = 1, TimeOff = 1;

void setup()
{
  lcd.begin(16, 2); //set up the LCD's number of columns and rows:
  pinMode(led, OUTPUT);
  pinMode(incrementButton, INPUT); //set incrementButton as INPUT
  pinMode(decrementButton, INPUT); //set decrementButton as INPUT
  pinMode(SelectButton, INPUT); //set decrementButton as INPUT

  lcd.setCursor(1,0);
  lcd.print("Time On"); //print a message on the LCD "Time On"
  lcd.setCursor(1,1); //Set the cursor at row 2 to print next line
  lcd.print("Time Off"); ////print a message on the LCD "Time Off"
  lcd.setCursor(0,1);
  lcd.print(">");
}//end of setup

void loop()
{
  incrementState = digitalRead(incrementButton); //read the increment button state
  decrementState = digitalRead(decrementButton); //read the decrement button state
  selectState = digitalRead(SelectButton); //read the Select button state

  if(selectState !=  lastSelectState) // lastSelectState will need to be declaired boolean too at the top of your code.
  {
    if(selectState == HIGH)
    {
      // Notice I put this in here and not outside the if statement.
      State = !State; // also declare boolean at the top of your code. Set to false
    }
    if(State)
    {
      lcd.setCursor(0,0);
      lcd.print(">");
      lcd.setCursor(0,1);
      lcd.print(" ");
    }
    else
    {
      lcd.setCursor(0,0);
      lcd.print(" ");
      lcd.setCursor(0,1);
      lcd.print(">");
    }

    lastSelectState = selectState;
  }

  if(incrementState != lastIncrementState) //compare increment button state to its last state
  {
    if(incrementState == HIGH)//increment button is pressed
    {
      //increment the counter
      if(State == HIGH)
        TimeOn++;
      else
        TimeOff++;
      delay(20); //debounce delay
    }
    lastIncrementState = incrementState;
  }

  if(decrementState != lastDecrementState)//compare decrement state to its lastState
  {
    if(decrementState == HIGH)//decrement button is pressed
    {
      //decrement the counter
      if(State == HIGH)
        TimeOn--;
      else
        TimeOff--;

      delay(20); //debounce delay
    }
    lastDecrementState = decrementState;
  }

  lcd.setCursor(10, 0);
  lcd.print(TimeOn); //print it on serial monitor       
  lcd.print("   "); //3 blank spaces
  lcd.setCursor(10, 1);
  lcd.print(TimeOff); //print it on serial monitor
  lcd.print("   "); //3 blank spaces

  LEDState();
}//end of loop

void LEDState()
{
  if(millis() - Ontime > (TimeOn * factor) && ON == true) // ON in this case looks to see if the LED itself is on. So before this IF statement is true, the LED is on
  {
    Offtime = millis(); // Notice it does not say Ontime, but instead it says Offtime. This is because when the
                        // LED is OFF, we want to start the timer to turn it back ON.
    digitalWrite(led, LOW);   // turn off LED
    ON = false;
  }
  if(millis() - Offtime > (TimeOff * factor) && ON == false) // LED is currently off, now keep counting to turn it on.
  {
    Ontime = millis();
    digitalWrite(led, HIGH);    // turn on LED
    ON = true;
  }
}
812  Using Arduino / Project Guidance / Re: Button Help, Up, Down, Select on: March 23, 2014, 09:55:01 pm
What menu items are you referring to? All I see are printed messages on your display, what exactly is getting changed?
813  Using Arduino / Project Guidance / Re: Ultrasonic Sensor Guidance on: March 23, 2014, 09:01:58 pm
It doesn't matter if they are physically connected or not, your code is setting those pins as outputs.
814  Using Arduino / Project Guidance / Re: Ultrasonic Sensor Guidance on: March 23, 2014, 08:57:49 pm
Is led 3 and 4 connected to the digital pins 1 and 0 or A1 an A0? If yours using the serial monitor then you shouldn't have anything in the digital pins 1 and 0, otherwise you will get unwanted results in the serial monitor.
815  Using Arduino / Project Guidance / Re: trying to connect 5 8x8 matrixes only 4 work.the first 1 from left does not. on: March 23, 2014, 08:15:32 pm
Try changing this unsigned long x to unsigned long long x
816  Using Arduino / Project Guidance / Re: trying to connect 5 8x8 matrixes only 4 work.the first 1 from left does not. on: March 23, 2014, 07:43:58 pm
Do all 5 displays work now?

What exactly are you trying to do, your original question was that your 5th display wasn't working.

This here is only sending it to four displays.
Quote
void printBufferLong(){
  for (int a=0;a<7;a++){                    // Loop 7 times for a 5x7 font
    unsigned long x = bufferLong [a*2+1];   // Get high buffer entry
    byte y = x;                             // Mask off first character
    lc.setRow(3,a,y);                       // Send row to relevent MAX7219 chip
    x = bufferLong [a*2];                   // Get low buffer entry
    y = (x>>24);                            // Mask off second character
    lc.setRow(2,a,y);                       // Send row to relevent MAX7219 chip
    y = (x>>16);                            // Mask off third character
    lc.setRow(1,a,y);                       // Send row to relevent MAX7219 chip
    y = (x>>smiley-cool;                             // Mask off forth character
    lc.setRow(0,a,y);                       // Send row to relevent MAX7219 chip

  }
}

Replace it with this and see if it works. I added in:  lc.setRow(4,a,y); .... y = (x>>32);  lc.setRow(3,a,y);

Code:
void printBufferLong(){
  for (int a=0;a<7;a++){                    // Loop 7 times for a 5x7 font
    unsigned long x = bufferLong [a*2+1];   // Get high buffer entry
    byte y = x;                             // Mask off first character
    lc.setRow(4,a,y);                       // Send row to relevent MAX7219 chip
    x = bufferLong [a*2];                   // Get low buffer entry
    y = (x>>32);                            // Mask off second character
    lc.setRow(3,a,y);                       // Send row to relevent MAX7219 chip
    y = (x>>24);                            // Mask off third character
    lc.setRow(2,a,y);                       // Send row to relevent MAX7219 chip
    y = (x>>16);                            // Mask off forth character
    lc.setRow(1,a,y);                       // Send row to relevent MAX7219 chip
    y = (x>>8);                             // Mask off fifth character
    lc.setRow(0,a,y);                       // Send row to relevent MAX7219 chip
  }
}
817  Using Arduino / Project Guidance / Re: trying to connect 5 8x8 matrixes only 4 work.the first 1 from left does not. on: March 23, 2014, 01:04:49 pm
Do you have the MaxMatrix library too? Most if not all my dot matrix sketches use both the Ledcontrol and MaxMatrix libraries.

But this is one I use to see if all the displays work.
Code:
//We always have to include the library
#include "LedControl.h"

/*
 Now we need a LedControl to work with.
 ***** These pin numbers will probably not work with your hardware *****
 pin 12 is connected to the DataIn
 pin 11 is connected to the CLK
 pin 10 is connected to LOAD
 ***** Please set the number of devices you have *****
 But the maximum default of 8 MAX72XX wil also work.
 */
LedControl lc=LedControl(12,11,10,4);

/* we always wait a bit between updates of the display */
unsigned long delaytime=10;
int devices;
/*
 This time we have more than one device.
 But all of them have to be initialized
 individually.
 */
void setup() {
  //we have already set the number of devices when we created the LedControl
  devices = lc.getDeviceCount();
  //we have to init all devices in a loop
  for(int address = devices - 1; address >= 0;address--)
  {
    /*The MAX72XX is in power-saving mode on startup*/
    lc.shutdown(address,false);
    /* Set the brightness to a medium values */
    lc.setIntensity(address,8);
    /* and clear the display */
    lc.clearDisplay(address);
  }
}

void loop()
{
  //we have to init all devices in a loop
  for(int address = devices - 1; address >= 0;address--)
  {
    for(int row=0;row<8;row++)
    {
      for(int col=0;col<8;col++)
      {
        delay(delaytime);
        lc.setLed(address,row,col,true);
        delay(delaytime);
        lc.setLed(address,row,col,false);
      }
    }
  }
}
818  Using Arduino / Programming Questions / Re: Stewart platform programming on: March 22, 2014, 04:32:27 pm
@MarkT
Well if he wants he can change the code to record say 60 movements (1 move per second), instead of 300. This will decrease the amount of ram used, significantly! He'll just need a timer and for that can use the millis function.
819  Using Arduino / Project Guidance / Re: Using a Fingerprint sensor and 3X4 keypad together on: March 22, 2014, 04:17:16 pm
Well being that there are no other delays in your sketch, the 4-5 second delay is coming from the fingerprint scanner library. And the only way to fix that would be to alter the fingerprint library and sorry, I am not going to do that. You would need to talk to the creator of the library and see if there are any ways to make it faster.
820  Using Arduino / Project Guidance / Re: Using a Fingerprint sensor and 3X4 keypad together on: March 22, 2014, 03:52:48 pm
Updated code, try it now.
821  Using Arduino / Project Guidance / Re: Using a Fingerprint sensor and 3X4 keypad together on: March 22, 2014, 03:24:13 pm
Your delays will block your code from doing anything until they are done, but this should work.
Code:
#include <Adafruit_Fingerprint.h>
#if ARDUINO >= 100
#include <SoftwareSerial.h>
#else
#include <NewSoftSerial.h>
#endif

#include <Password.h>

#include <Keypad.h>


//int getFingerprintIDez();
int led = 13;
boolean Password_is_valid = false;

// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino  (WHITE wire)
#if ARDUINO >= 100
SoftwareSerial mySerial(2, 3);
#else
NewSoftSerial mySerial(2, 3);
#endif

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

Password password = Password( "1234" );

const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
  {
    '1','2','3'      }
  ,
  {
    '4','5','6'      }
  ,
  {
    '7','8','9'      }
  ,
  {
    '*','0','#'      }
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = {
  9, 8, 7, 6 };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = {
  12, 11, 10 };


// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );


void setup() 
{
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(led, OUTPUT);
  Serial.begin(9600);
  Serial.println("fingertest");
  keypad.addEventListener(keypadEvent); //add an event listener for this keypad
  keypad.setDebounceTime(100);

  // set the data rate for the sensor serial port
  finger.begin(57600);

  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  }
  else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1);
  }
  Serial.println("Waiting for valid finger...");
}

void loop()                     // run over and over again
{
  char eKey = keypad.getKey();
  getFingerprintIDez();
 
  if(Password_is_valid) // check to see if either the finger or password is valid
    PasswordIsValid();
}

//uint8_t getFingerprintID() {
//  uint8_t p = finger.getImage();
//  switch (p) {
//  case FINGERPRINT_OK:
//    Serial.println("Image taken");
//    break;
//  case FINGERPRINT_NOFINGER:
//    Serial.println("No finger detected");
//    return p;
//  case FINGERPRINT_PACKETRECIEVEERR:
//    Serial.println("Communication error");
//    return p;
//  case FINGERPRINT_IMAGEFAIL:
//    Serial.println("Imaging error");
//    return p;
//  default:
//    Serial.println("Unknown error");
//    return p;
//  }
//
//  // OK success!
//
//  p = finger.image2Tz();
//  switch (p) {
//  case FINGERPRINT_OK:
//    Serial.println("Image converted");
//    break;
//  case FINGERPRINT_IMAGEMESS:
//    Serial.println("Image too messy");
//    return p;
//  case FINGERPRINT_PACKETRECIEVEERR:
//    Serial.println("Communication error");
//    return p;
//  case FINGERPRINT_FEATUREFAIL:
//    Serial.println("Could not find fingerprint features");
//    return p;
//  case FINGERPRINT_INVALIDIMAGE:
//    Serial.println("Could not find fingerprint features");
//    return p;
//  default:
//    Serial.println("Unknown error");
//    return p;
//  }
//
//  // OK converted!
//  p = finger.fingerFastSearch();
//  if (p == FINGERPRINT_OK) {
//    Serial.println("Found a print match!");
//  }
//  else if (p == FINGERPRINT_PACKETRECIEVEERR) {
//    Serial.println("Communication error");
//    return p;
//  }
//  else if (p == FINGERPRINT_NOTFOUND) {
//    Serial.println("Did not find a match");
//    return p;
//  }
//  else {
//    Serial.println("Unknown error");
//    return p;
//  }   
//
//  // found a match!
//  Serial.print("Found ID #");
//  Serial.print(finger.fingerID);
//  Serial.print(" with confidence of ");
//  Serial.println(finger.confidence);
//}

// returns -1 if failed, otherwise returns ID #

int getFingerprintIDez() {
  //  uint8_t p = finger.getImage();
  //  if (p != FINGERPRINT_OK)  return -1;
  //
  //  p = finger.image2Tz();
  //  if (p != FINGERPRINT_OK)  return -1;
  //
  //  p = finger.fingerFastSearch();
  //  if (p != FINGERPRINT_OK)  return -1;

  if((finger.getImage() | finger.image2Tz() | finger.fingerFastSearch() ) != FINGERPRINT_OK)
    return -1;
  else
  {
    // found a match!
    Password_is_valid = true;
    Serial.print("Found ID #");
    Serial.print(finger.fingerID);
    Serial.print(" with confidence of ");
    Serial.println(finger.confidence);
    return finger.fingerID;
  }
}

//take care of some special events
void keypadEvent(KeypadEvent eKey)
{
  switch (keypad.getState())
  {
  case PRESSED:
    Serial.print("Pressed: ");
    Serial.println(eKey);
    switch (eKey)
    {
    case '#':
      guessPassword();
      break;
    default:
      password.append(eKey);
    }
  }
}

void guessPassword()
{
  Serial.print("Guessing password... ");
  if (password.evaluate())
  {
    Serial.println("VALID PASSWORD "); //
    Password_is_valid = true;
    password.reset(); //resets password after correct entry
  }
  else
  {
    Serial.println("INVALID PASSWORD ");
    password.reset(); //resets password after INCORRECT entry
  }
}

void PasswordIsValid()
{
  digitalWrite(5, HIGH);
  delay(1000);
  digitalWrite(4, HIGH);
  delay(1000);
  digitalWrite(4, LOW);
  delay(25000);
  digitalWrite(5, LOW);
 
  Password_is_valid = false;
}
822  Using Arduino / Programming Questions / Re: Stewart platform programming on: March 22, 2014, 03:01:29 pm
Look at the record function, it gets a value from one pot and stores it's value in an array, what you need to do is add in 5 more pots and use a 2D array like servoPos[6][300]. 6 elements total (pots), with 300 indexes each. If your stuck on how arrays work then look at the example provided in the arduino software. Examples -> 05.Control -> Arrays

Quote
void recordFunction ( )
{
  Serial.println ("Record function");                    // if so - prints record
  delay(15);
  for (int i=0;i<299;i++)                            //for loop to store 300 values of pot 
  {
    val = analogRead(potpin);                  // reads the value of the potentiometer (value between 0 and 1023)
    val = map(val, 0, 1023, 44, 134);                  // scale it to use it with the servo (value between 0 and 180) ??? this statement is false
    myservo.write(val);                              // sets the servo position according to the scaled value
    servoPos [ i ]=val;                                  // stores val in array "servoPos
    delay(15);                                                  // waits for the servo to get there
    Serial.println(val);                          // print values for checking
  } 
}
823  Using Arduino / Project Guidance / Re: Using a Fingerprint sensor and 3X4 keypad together on: March 22, 2014, 02:46:21 pm
Yes, it is possible to do.
However your combination code appears the be wrong, but it also depends on what you want to read first, the finger or the password?

Usually you would check the finger print first then get the password, however you could also do it the other way and get the password first.

What are you trying to do?
824  Using Arduino / Programming Questions / Re: Problem debouncing multiple buttons on: March 21, 2014, 05:03:14 pm
I dont have your LCD, so I can't do any tests to see why its not working.

Quote
I'm not sure what you are asking. The array buttonNumber[ i ] has the numbers 0-7 in it and never changes. The loop cycles through 0-7.
What I'm asking is why use an array with 0-7 in it, when you can just use the FOR loop that already cycles through 0-7. There is no difference of the 0-7 in the array to the 0-7 in the FOR loop, so why add in something that is not needed?
825  Using Arduino / Project Guidance / Re: NEED HELP! Stuck 4X3 keypad access code sketch on: March 21, 2014, 03:31:49 pm
If the library is in the correct spot then what arduino software version are you using? Make sure the Keypad.h file does not have WProgram.h in it, and if it does then you need to change it to Arduino.h and save it.

If you still get errors then you need to post pictures, screenshots of where the library is and the errors your getting. Make sure the pictures are a reasonable size, nothing like 2000x2000.
Pages: 1 ... 53 54 [55] 56 57 ... 242