Jump to content
ELFORUM - Forumul electronistilor

Arduino KEYPAD code


Recommended Posts

Buna seara.Lucrez la un nou proiect,un keypad format din 4 butoane,primele 3 sunt cifrele ce vor forma codul iar cel de-al 4 lea reseteaza variabila in care se stocheaza butonul ce a fost apasat.

Initial l-am facut in asa fel incat la apasarea unui buton sa trimita cifra corespunzatoare pe serial,o citesc intr-un textbox (VB.net) si o aloc unei variabile dar din pacate m-am blocat,nu stiu cum sa adaug valoare dupa valoare unei variabile asa ca m-am gandit sa stochez parola in uc iar daca e corecta sa-mi trimita pe serial "parola corecta" / "parola incoreta".Eu voi posta programul initial si am rugamintea sa ma ajutati in a modifica codul.

 

void setup(){ Serial.begin(9600);//Initiliazeaza trimiterea datelorpinMode(3, OUTPUT);//Led pentru apasarea butonului de resetpinMode(2, OUTPUT);//Led pentru apasarea celor 3 butoanepinMode(8, INPUT); //Seteaza pinii 8...11 ca si intraripinMode(9, INPUT);pinMode(10, INPUT);pinMode(11, INPUT);delay(2000); }void loop(){if (digitalRead(8)==LOW)//Se verifica starea pinilor si se trimit date catre PC{delay(20);}else if (digitalRead(8)==HIGH){Serial.println("1");digitalWrite(3, HIGH);delay(50);digitalWrite(3, LOW);}delay(20);if (digitalRead(9)==LOW){delay(20);}else if (digitalRead(9)==HIGH){Serial.println("2");digitalWrite(3, HIGH);delay(50);digitalWrite(3, LOW);}delay(20);if (digitalRead(10)==LOW){delay(20);}else if (digitalRead(10)==HIGH){Serial.println("3");digitalWrite(3, HIGH);delay(50);digitalWrite(3, LOW);}delay(20);if (digitalRead(11)==LOW){delay(20);}else if (digitalRead(11)==HIGH){Serial.println("R");digitalWrite(2, HIGH);delay(50);digitalWrite(2, LOW);}}
COD VB

Public Class Form1    Dim Ucod As String    Dim Cod As String    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load        SerialPort1.Open()        Timer1.Enabled = True    End Sub    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick        TextBox1.Text = Ucod    End Sub    Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived        Ucod = SerialPort1.ReadLine        ' Timer1.Enabled = True    End Sub End Class
Am postat si codul din vb,problema in vb este ca nu reusesc sa afisez datele ce vin de pe serial una dupa cealalta ci se afiseaza doar ultima cifra.Daca folosesc textbox1.text=textbox1.text & ucod ,la apasarea unui buton cifra se va repeta la infinit
Link to comment
  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Am rezolvat-o cu VB,postez codul...poate va mai avea nevoie cineva

 

Public Class Form1    Dim Ucod As String    Dim Cod As String    Dim Mcod, Xcod As String    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load        Cod = "1321"        TextBox3.Text = "1321"        SerialPort1.Open()        Timer1.Enabled = True    End Sub    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick        TextBox1.Text = Ucod        RichTextBox1.Text = Xcod    End Sub    Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived        Ucod = SerialPort1.ReadLine        SerialPort1.DiscardInBuffer()        Ucod = Mid(Ucod, 1, 1)        Xcod = Xcod + Ucod        If Len(Xcod) = 4 Then            If Xcod = TextBox3.Text Then                'My.Computer.Audio.Play("C:\corect.Wav")                MsgBox("Cod Acces Corect")            Else                My.Computer.Audio.Play("C:\gresit.Wav")                'MsgBox("Cod Acces Incorect")            End If            Xcod = ""                  End If    End Sub        End Class
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.Terms of Use si Guidelines