Show Posts
|
|
Pages: [1] 2 3 ... 7
|
|
2
|
Using Arduino / Networking, Protocols, and Devices / Re: Xbee Found Bootloader active reprogramming firmware
|
on: March 24, 2013, 10:09:09 pm
|
|
this happen when i tried to program the xbee. i modified the modem configuration. then, while on the programming modem process, it suddenly crash. i've set the baud rate yo 9600. default baud rate. both baud rate in modem configuration & pc setting is 9600. i wonder how this happen. i manage to program 2 xbee modules. only 1 undergo this error. by the way, i try to change the baud rate to 57600, the same error happen while programming the xbee.
|
|
|
|
|
4
|
Using Arduino / Programming Questions / Re: TX command code & RX respond code of module via serial com
|
on: January 25, 2013, 01:35:44 am
|
You could make that a 2D array, instead. Then, one argument would be an index that would define which row to use.
Or. use a switch statement to select which array to send. But, don't write 5 functions.
2D array? i think my experience in programming is just shallow. by the way, for the switch case. i understand that one. i'm gonna try it. but, perhaps i could learn how to do 2D array.
|
|
|
|
|
6
|
Using Arduino / Programming Questions / Re: TX command code & RX respond code of module via serial com
|
on: January 23, 2013, 12:10:10 pm
|
below code is already functioning. but, may i ask. is there any other way that i can make the code become less line. i think there is another way. but, i don't have any idea how to do it. i think the value of adc_key_in can be made into for loop so that if counter 0, it will call function deleteFinger0(); but i don't have any clue on how to do it. i would be glad if someone could give me a hint on how to do it. thank you. //========================================================================== // Author : CYTRON TECHNOLOGIES SDN BHD // Project : Arduino Duemilanove // Project description : Project_1: "Hello World" and utilize switch //==========================================================================
#include <LiquidCrystal.h>
/* The circuit: * LCD RS pin to digital pin 8 * LCD Enable pin to digital pin 9 * LCD D4 pin to digital pin 4 * LCD D5 pin to digital pin 5 * LCD D6 pin to digital pin 6 * LCD D7 pin to digital pin 7 * LCD R/W pin to ground */
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int analogPin = A0; int adc_key_old; int adc_key_in; int NUM_KEYS = 5; int key=-1; int adc_key_val[5] ={30, 150, 360, 535, 760 }; byte deleteFingerPrint0[] = {0x4D, 0x58, 0x10, 0x03, 0x42, 0x00, 0x00, 0xFA}; // 8 bytes byte deleteFingerPrint1[] = {0x4D, 0x58, 0x10, 0x03, 0x42, 0x00, 0x01, 0xFB}; // 8 bytes byte deleteFingerPrint2[] = {0x4D, 0x58, 0x10, 0x03, 0x42, 0x00, 0x02, 0xFC}; // 8 bytes byte deleteFingerPrint3[] = {0x4D, 0x58, 0x10, 0x03, 0x42, 0x00, 0x03, 0xFD}; // 8 bytes byte deleteFingerPrint4[] = {0x4D, 0x58, 0x10, 0x03, 0x42, 0x00, 0x04, 0xFE}; // 8 bytes
byte respondCorrect[] = {0x4D, 0x58, 0x30, 0x01, 0x01, 0xD7}; // 6 bytes
byte operationSuccessDelete[] = {0x4D, 0x58, 0x30, 0x02, 0x42, 0x31, 0x4A}; // 7 bytes byte parameterErrorDelete [] = {0x4D, 0x58, 0x30, 0x02, 0x42, 0x35, 0x4E}; // 7 bytes byte respond[6],operation[7],a,f,g; /******************************************************************************* * PRIVATE FUNCTION: setup() * * PARAMETERS: * ~ void * * RETURN: * ~ void * * DESCRIPTIONS: * Define of I/O pin as Input or Output * *******************************************************************************/ // The setup() method runs once, when the sketch starts void setup () { // initialize serial: Serial.begin(57600); lcd.begin(16, 2); // set the lcd dimension lcd.print(" CYTRON TECH."); // display the text lcd.setCursor(0,1); // set lcd.setCursor (column,row) lcd.print(" Eg. LCD Shield"); delay(1500); // delay for 3000ms lcd.clear(); adc_key_old = analogRead(analogPin); // store the unpress key value }
/******************************************************************************* * PRIVATE FUNCTION: loop() * * PARAMETERS: * ~ void * * RETURN: * ~ void * * DESCRIPTIONS: * Non-Stop looping * *******************************************************************************/ void loop() { lcd.setCursor(0,0); lcd.print("Fingerprint Reader"); lcd.setCursor(0,1); lcd.print("Select Address");
adc_key_in = analogRead(analogPin); // read ADC value adc_key_in = get_key(adc_key_in); if (adc_key_in==0) { deleteFinger0(); correctRespond(); operationSuccesful(); } else if (adc_key_in==1) { deleteFinger1(); correctRespond(); operationSuccesful(); } else if (adc_key_in==2) { deleteFinger2(); correctRespond(); operationSuccesful(); }
else if (adc_key_in==3) { deleteFinger3(); correctRespond(); operationSuccesful(); }
else if (adc_key_in==4) { deleteFinger4(); correctRespond(); operationSuccesful(); } }
/******************************************************************************* * PRIVATE FUNCTION: get_key * * PARAMETERS: * ~ integer * * RETURN: * ~ unsigned int input * * DESCRIPTIONS: * convert the ADC value to number between 0 to 4 * *******************************************************************************/ int get_key(unsigned int input) { int k; for (k = 0; k < NUM_KEYS; k++) { if (input < adc_key_val[k]) { return k; } } if (k >= NUM_KEYS) k = -1; // No valid key pressed return k; }
void deleteFinger0(){ // set the cursor to column 0, line 1 lcd.setCursor(0, 1); // Print a message to the LCD. lcd.print("Del Fingerprint1");
// write the 8bytes array of the command code Serial.write(deleteFingerPrint0, sizeof(deleteFingerPrint0)); delay(1500); }
void deleteFinger1(){ // set the cursor to column 0, line 1 lcd.setCursor(0, 1); // Print a message to the LCD. lcd.print("Del Fingerprint2");
// write the 8bytes array of the command code Serial.write(deleteFingerPrint1, sizeof(deleteFingerPrint1)); delay(1500); }
void deleteFinger2(){ // set the cursor to column 0, line 1 lcd.setCursor(0, 1); // Print a message to the LCD. lcd.print("Del Fingerprint3");
// write the 8bytes array of the command code Serial.write(deleteFingerPrint2, sizeof(deleteFingerPrint2)); delay(1500); }
void deleteFinger3(){ // set the cursor to column 0, line 1 lcd.setCursor(0, 1); // Print a message to the LCD. lcd.print("Del Fingerprint4");
// write the 8bytes array of the command code Serial.write(deleteFingerPrint3, sizeof(deleteFingerPrint3)); delay(1500); }
void deleteFinger4(){ // set the cursor to column 0, line 1 lcd.setCursor(0, 1); // Print a message to the LCD. lcd.print("Del Fingerprint5");
// write the 8bytes array of the command code Serial.write(deleteFingerPrint4, sizeof(deleteFingerPrint4)); delay(1500); }
void correctRespond() { // Now, reply contains all 6 bytes for(byte x=0; x<6; x++) { while(Serial.available() == 0) {}; // Wait for a byte respond[x] = Serial.read(); a = memcmp(respondCorrect, respond, sizeof(respondCorrect));
if (a==0) { lcd.clear(); // set the cursor to column 0, line 0 lcd.setCursor(0, 0); // Print a message to the LCD. lcd.print("Correct Respond"); } else { lcd.clear(); // set the cursor to column 0, line 0 lcd.setCursor(0, 0); // Print a message to the LCD. lcd.print("Wrong Respond"); } } delay(1500); }
void operationSuccesful () { // Now, reply contains all 7 bytes for(byte x=0; x<7; x++) { while(Serial.available() == 0) {}; // Wait for a byte operation[x] = Serial.read(); f = memcmp(operationSuccessDelete, operation, sizeof(operationSuccessDelete)); g = memcmp(parameterErrorDelete, operation, sizeof(parameterErrorDelete)); if (f==0) { lcd.clear(); // set the cursor to column 0, line 0 lcd.setCursor(0, 0); // Print a message to the LCD. lcd.print("Operation Success"); } else if (g==0) { lcd.clear(); // set the cursor to column 0, line 0 lcd.setCursor(0, 0); // Print a message to the LCD. lcd.print("Parameter Error"); } else { lcd.clear(); // set the cursor to column 0, line 0 lcd.setCursor(0, 0); // Print a message to the LCD. lcd.print("Please Restart"); } } delay(1500); }
|
|
|
|
|
8
|
Using Arduino / Programming Questions / Re: need help to modify this push button code
|
on: January 21, 2013, 09:29:29 pm
|
(currentState == 1); does nothing. Actually not quite true, but not what you want currentState = 1; sets the currentState variable to 1
== compares 2 things = sets the variable on the left to the value on the right.
actually not quite true? i think my coding is like this. my initial state is zero by the way. currentState = 0; sets the currentState variable to 1
|
|
|
|
|
9
|
Using Arduino / Programming Questions / Re: need help to modify this push button code
|
on: January 21, 2013, 04:46:17 am
|
am i correct like this? but why it not goes to state 1. remain at state zero after i push down button. ///////////////////////////////////////////////////////////// if (currentState == 0 && buttonPressed == DOWN_BUTTON_MENU) { (currentState == 1); lcd.clear(); lcd.setCursor(0,0); // set lcd.setCursor (column,row) lcd.print("Add Fingerprint"); } else if (currentState == 1 && buttonPressed == DOWN_BUTTON_MENU) { (currentState == 2); lcd.clear(); lcd.setCursor(0,0); // set lcd.setCursor (column,row) lcd.print("Delete"); lcd.setCursor(0,1); // set lcd.setCursor (column,row) lcd.print("Fingerprint"); } else if (currentState == 2 && buttonPressed == DOWN_BUTTON_MENU) { (currentState == 3); lcd.clear(); lcd.setCursor(0,0); // set lcd.setCursor (column,row) lcd.print("Search"); lcd.setCursor(0,1); // set lcd.setCursor (column,row) lcd.print("Fingerprint"); } else if (currentState == 3 && buttonPressed == DOWN_BUTTON_MENU) { (currentState == 4); lcd.clear(); lcd.setCursor(0,0); // set lcd.setCursor (column,row) lcd.print("Empty Database"); } else if (currentState == 4 && buttonPressed == DOWN_BUTTON_MENU) { //(currentState == 0); lcd.clear(); lcd.setCursor(0,0); // set lcd.setCursor (column,row) lcd.print("Search Database"); } ///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
11
|
Using Arduino / Programming Questions / Re: need help to modify this push button code
|
on: January 21, 2013, 04:08:05 am
|
i believe more visible like this. i understand what u meant. almost got it. but how to link the state while i pressed the down button. if (currentState == 1 && buttonPressed == DOWN_BUTTON_MENU) { lcd.clear(); lcd.setCursor(0,0); // set lcd.setCursor (column,row) lcd.print("Add Fingerprint"); }
else if (currentState == 2 && buttonPressed == DOWN_BUTTON_MENU) { lcd.clear(); lcd.setCursor(0,0); // set lcd.setCursor (column,row) lcd.print("Delete"); lcd.setCursor(0,1); // set lcd.setCursor (column,row) lcd.print("Fingerprint"); }
else if (currentState == 3 && buttonPressed == DOWN_BUTTON_MENU) { lcd.clear(); lcd.setCursor(0,0); // set lcd.setCursor (column,row) lcd.print("Search"); lcd.setCursor(0,1); // set lcd.setCursor (column,row) lcd.print("Fingerprint"); }
else if (currentState == 4 && buttonPressed == DOWN_BUTTON_MENU) { lcd.clear(); lcd.setCursor(0,0); // set lcd.setCursor (column,row) lcd.print("Empty Database"); }
else if (currentState == 5 && buttonPressed == DOWN_BUTTON_MENU) { lcd.clear(); lcd.setCursor(0,0); // set lcd.setCursor (column,row) lcd.print("Search Database"); }
|
|
|
|
|
13
|
Using Arduino / Programming Questions / Re: need help to modify this push button code
|
on: January 20, 2013, 09:53:36 pm
|
by the way, is this code correct in your opinion. i manage to scroll down to every operation. add fingerprint, delete fingerprint and so on. by when i want to go to second menu, it won't go to the second menu. need advice on that. perhaps maybe something wrong with my coding. #include <LiquidCrystal.h> #define RIGHT_BUTTON_MENU 0 #define UP_BUTTON_MENU 1 #define DOWN_BUTTON_MENU 2 #define LEFT_BUTTON_MENU 3 #define SELECT_BUTTON_MENU 4
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int analogPin = A0; int adc_key_old; int NUM_KEYS = 5; int key=-1; int adc_key_val[5] ={30, 150, 360, 535, 760};
// Variables will change: int adc_key_in=0; int adc_key_in_last = 0; // previous state of the button int adc_key_in_PushCounter = 0; // counter for the number of button presses
int State1 = 0; int State2 = 0; int State3 = 0; int State4 = 0; int State5 = 0; int State6 = 0; int State7 = 0;
void setup () { // initialize serial: Serial.begin(57600); lcd.begin(16, 2); // set the lcd dimension lcd.setCursor(0,0); lcd.print(" CYTRON TECH."); // display the text lcd.setCursor(0,1); // set lcd.setCursor (column,row) lcd.print(" Eg. LCD Shield"); delay(1500); // delay for 1500ms lcd.clear(); adc_key_old = analogRead(analogPin); // store the unpress key value }
void loop() {
adc_key_in = analogRead(analogPin); // read ADC value adc_key_in = get_key(adc_key_in); // compare the buttonState to its previous state if (adc_key_in != adc_key_in_last) { // if the state has changed, increment the counter if (adc_key_in == DOWN_BUTTON_MENU) {
// if the current state is HIGH then the button // wend from off to on: adc_key_in_PushCounter++; delay (300); if (adc_key_in_PushCounter==1) { //{State1 = 1} lcd.clear(); lcd.setCursor(0,0); // set lcd.setCursor (column,row) lcd.print("Add Fingerprint"); if (adc_key_in == SELECT_BUTTON_MENU) { addFinger0; } } else if (adc_key_in_PushCounter==2){ lcd.clear(); lcd.setCursor(0,0); // set lcd.setCursor (column,row) lcd.print("Delete"); lcd.setCursor(0,1); // set lcd.setCursor (column,row) lcd.print("Fingerprint"); } else if (adc_key_in_PushCounter==3){ lcd.clear(); lcd.setCursor(0,0); // set lcd.setCursor (column,row) lcd.print("Search"); lcd.setCursor(0,1); // set lcd.setCursor (column,row) lcd.print("Fingerprint"); }
else if (adc_key_in_PushCounter==4){ lcd.clear(); lcd.setCursor(0,0); // set lcd.setCursor (column,row) lcd.print("Empty Database"); }
else if (adc_key_in_PushCounter==5){ lcd.clear(); lcd.setCursor(0,0); // set lcd.setCursor (column,row) lcd.print("Search Database"); } } else { // if the current state is LOW then the button // wend from on to off: //lcd.setCursor(0,0); // set lcd.setCursor (column,row) //lcd.print("off"); } } // save the current state as the last state, //for next time through the loop adc_key_in_last = adc_key_in; }
int get_key(unsigned int input) { int k;
for (k = 0; k < NUM_KEYS; k++) { if (input < adc_key_val[k]) {
return k; } } if (k >= NUM_KEYS) k = -1; // No valid key pressed
return k; }
void addFinger0(){ // set the cursor to column 0, line 1 lcd.setCursor(0, 1); // Print a message to the LCD. lcd.print("Add Fingerprint1"); delay(1500); }
|
|
|
|
|