Recent Posts

Pages: 1 ... 8 9 [10]
91
On the same lines of your program UKHeliBob ,I wrote this program for password , the LCD successfully print "Enter password",confirming that we are in the VOID SETPASSWORD loop.
However,when in this loop, i press enter, the PrintKey case is never performed, rather it prints the ENTER Key value.

What changes should i make?
Please refer the Void SetPassword loop at the very end of program.

Regarding what PaulS pointed out, I know that
Quote
If there is data to be read from the keyboard object, the body of the if statement will be executed. If not, the else if statement will be evaluated.
I agree it is foolish of me,but i really don't want any possible combination left untried. :)

The Code:
Code: [Select]
#include <LiquidCrystal.h>
#include <PS2Keyboard.h>

#define KeyRead 0
#define PrintKey 1

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 13, 14, 15, 16, 17);

const int DataPin = 2;
const int IRQpin =  3;


PS2Keyboard keyboard;

char KbChars;
char array[50];
char KeyStore[6];
char inByte;
int i=0;

void setup() {

  lcd.begin(16, 2);
  delay(100);
  keyboard.begin(DataPin, IRQpin);
  i=0;
  lcd.setCursor(0, 0);
  lcd.print("Input Message:");
  lcd.setCursor(0,1);
 }

void loop() {
 
//Blinking 
  lcd.noCursor();
  delay(100);
  lcd.cursor();
  delay(100);
//Blinking
 
   if (keyboard.available()) {
  KbChars=keyboard.read();
 
  if (KbChars == PS2_ESC)
      {
      lcd.clear();
      delay(500);
      setup();
      }
  if (KbChars == PS2_TAB) {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Ciphered Text:");
      lcd.setCursor(0, 1);
      rot13();
      lcd.print(array);
    }

//////////////////////PASSWORD/////////////////////////   
  if(KbChars == PS2_PAGEUP){
        SetPassword();
        }
 //////////////////////PASSWORD///////////////////////// 
   
    array[i]=KbChars;
    i++;
    array[i]='\0';
    lcd.print(KbChars);
  }
}
   

void rot13() {

         for (int i = 0; i <= 50; ++i) { 
            inByte = array[i];
       if (!inByte) return; //end of string reached
         
        if (inByte >= 'A' && inByte <= 'M')
            inByte +=13;
        else if (inByte >= 'a' && inByte <= 'm')
            inByte +=13;
        else if (inByte >= 'N' && inByte <= 'Z')
            inByte -=13;
        else if (inByte >= 'n' && inByte <= 'z')
            inByte -=13;
        array[i] = inByte;
     }
    }
   
   
void SetPassword(){
   static int  state = KeyRead;  // initial state is 1, the "idle" state.
   
   switch (state)
  {
    case KeyRead:
    if (keyboard.available)    //user has pressed a key
      {
       
        char KeyFromKeybd = keyboard.read();    //read the user input
        if (KbChars == PS2_ENTER)      //was it ENTER ?
        {
          state = PrintKey;          //if it was then change state
        }
         else
        {
          KeyStore[i] = KeyFromKeybd;        //otherwise put the user input into the array
          i++;
          KeyStore[i] = '\0';           //terminate the array
        }
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Set Password:");
        lcd.setCursor(0,1);
        lcd.print(KeyFromKeybd);
        break;
      }
       case PrintKey:      //print what the user input
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Password is..");
      lcd.setCursor(0,1);
      lcd.print(KeyStore);
      i = 0;                   //reset the index to the array
      state = KeyRead;
      break;
  }
}
   
92
Programming Questions / Re: Arduino Update in MySQL
Last post by PaulS - Today at 03:33 pm
Quote
this code I would like that when is HIGH update the database to 1 and when it is LOW update to 0.
When what is HIGH? Or LOW?

Code: [Select]
char query_4[80];

   sprintf(query_4, "update minhacas_a.usuario1 SET position = '%d' where id_rele = 1;", somethingThatIsHIGHOrLOW);
93
Français / Re: Besoin d'aide (ruban led p...
Last post by mikafed26 - Today at 03:33 pm
merci à tous pour vos réactions, je vais essayer deux trois solutions.

pour répondre a la question infobarquee, je veut pouvoir l'allumer et l'éteindre quand j'en ai envie enfait, alors oui ça ferait la même chose qu'un interrupteur mais pourquoi faire simple quand on peut faire compliqué ^^
quel est l'avantage d'un détecteur de distance?

merci erwin38 pour ton lien mais j'y suis deja passé dessus sans avoir pu resoudre mon probleme :
94
Megatopic / Re: Modulo Wi-Fi ESP8266
Last post by SmallG - Today at 03:32 pm
va' collegato cosi'


Ottimo, è possibile sapere cosa comporta/a cosa serve quel filo che va sia al ground che verso nient'altro? Perché non basta il solo ground?

Sto provando a collegarlo anche in fisico così:




È giusto il pinout che dici, ma l'hai collegato al contrario, mettendo 5V su GND e GND sull'input!
Non so, forse è sbagliato il componente che ho importato su fritzing, perché andando lì col filo mi segna IN in alto.

Non è che perché devi scambiare pochi dati puoi collegarlo a caso ;). Devi sistemare tutte le cose che ti abbiamo fatto notare. Per i condensatori prova pure senza, ma ordinali e appena possibile aggiungili, questo voleva essere il senso del messaggio precedente.

Per il codice usa la libreria e guarda i suoi esempi, coprono molti dei casi di utilizzo.
Certo, mi sono spiegato male. Intendevo che volevo lasciare i condensatori/dioidi anche se dici che potrebbero non servire, proprio per evitare che perda in stabilità.

Sto procedendo con la 1 perché di questa ho tutto, mentre devo lasciare per ora da parte la soluzione 2 in quanto mi mancano gli ultimi componenti che hai citato, e come giustamente mi confermi, meglio evitare collegamenti a caso se mancano pezzi. :D
Sicuramente li ordiniamo se la soluzione 1 non offre i risultati sperati.

Grazie ancora!
95
Programming Questions / Re: boolean array
Last post by medeloualidi - Today at 03:32 pm
UKHeliBob yes exactly that what I want to do,
96
Deutsch / Re: Arduino Konstantstromquell...
Last post by DrDiettrich - Today at 03:32 pm
Dann tut es jetzt also, und die Spannungsdifferenz zwischen -Vin und Arduino Gnd ist 0V?

Wenn's ganz dumm geht, dann hast Du den PWM-Ausgang geschlachtet - ggf. anderen Pin ausprobieren.
97
so below i attached what i have now, put the resistors back in series.. also attached my code based on putting together many other things from this forum that i had found on debouncing and state changes. on a side note my Arduino is now not being read by my computer either... this is a pain in the a$# project .. lol one thing leads to another.
98
Project Guidance / Re: pullup LED
Last post by Tinkerspy - Today at 03:32 pm
I think this should work. Both buttons must be pressed for the led to come on. The buttons works as toggles in conjunction with the 'bit' machine. The controller checks the bits and switches the led on/off according to their state.

Code: [Select]

#include <Automaton.h>

Atm_button button1, button2;
Atm_controller ctl;
Atm_bit bit1, bit2;
Atm_led led;
Appliance app;

void setup() {
  app.component( led.begin( 4 ) );
  app.component(
    ctl.begin()
  .IF( bit1 ).AND( bit2 )
  .onChange( true, led, led.EVT_ON )
  .onChange( false, led, led.EVT_OFF )
  );
  app.component( bit1.begin() );
  app.component( bit2.begin() );
  app.component( button1.begin( 2 ).onPress( bit1, bit1.EVT_TOGGLE ) );
  app.component( button2.begin( 3 ).onPress( bit2, bit2.EVT_TOGGLE ) );
}

void loop() {
  app.run();
}




https://github.com/tinkerspy/Automaton/wiki
99
Deutsch / Re: kann man das schöner schre...
Last post by Eisebaer - Today at 03:32 pm
hi,

Code: [Select]
nThrottleIn=nThrottleIn<=920 ? 900 : (nThrottleIn>=2080 ? 2100:nThrottleIn)


ich liebe solche dinge, um kollegen in der firma zu beeindrucken, aber ein halbes jahr später ist es dann schwer, den eigenen code nachzuvollziehen.

irgendwie begeht man auch den fehler, zu glauben, daß kürzerer quellcode das programm schneller macht.

für mich ist das eher ein fall für eine eigene funktion. so bleibt's übersichtlich.

gruß stefan

PS.: aber ist ja richtig, die frage war "schöner", also insofern war theseus' lösung die bisher schönste...
100
Programming Questions / Re: Question about Strings!
Last post by xenoneng - Today at 03:32 pm
Thanks a lot. My problem solved with your help. :-)
Pages: 1 ... 8 9 [10]

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy