{"id":1309,"date":"2024-05-28T08:00:00","date_gmt":"2024-05-28T06:00:00","guid":{"rendered":"https:\/\/www.fuhselab.de\/?p=1309"},"modified":"2025-05-27T13:11:41","modified_gmt":"2025-05-27T11:11:41","slug":"arduino-tastenfeld-2","status":"publish","type":"post","link":"https:\/\/www.fuhselab.de\/index.php\/2024\/05\/28\/arduino-tastenfeld-2\/","title":{"rendered":"Arduino Tastenfeld 2"},"content":{"rendered":"\n<p>Es geht mit Tastenfeldern weiter und der Programmcode wird etwas angepasst\u2026<\/p>\n\n\n\n<!--more-->\n\n\n\n<p><strong>Programmierung 2 mit angepasstem Code:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include \"Keypad.h\"\nconst byte ROWS = 4;\nconst byte COLS = 3;\n\nchar keys&#91;ROWS]&#91;COLS] =\n{\n{'1','2','3'},\n{'4','5','6'},\n{'7','8','9'},\n{'*','0','#'}\n};\n\nbyte rowPins&#91;ROWS] = {5,6,7,8};\nbyte colPins&#91;COLS] = {2,3,4};\n\nKeypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);\n\nchar PIN&#91;6]={'1','2','3','4','5','6'}; \/\/ Die Geheimzahl\nchar attempt&#91;6]={0,0,0,0,0,0};\nint z=0;\n\nvoid setup()\n{\nSerial.begin(9600);\n}\n\nvoid correctPIN() \/\/ wird bei korrekter PIN ausgef\u00fchrt\n{\nSerial.println(\"richtige PIN eingegeben\");\n}\n\nvoid incorrectPIN()\n{\nSerial.println(\"falsche PIN eingegeben\");\n}\n\nvoid checkPIN()\n{\nint correct=0;\n\nint i;\nfor(i=0; i&lt;6; i++)\n{\nif(attempt&#91;i]==PIN&#91;i])\n{\ncorrect++;\n}\n}\n\nif (correct==6)\n{correctPIN();\n}\n\nelse\n{\nincorrectPIN();\n}\nfor (int zz=0; zz&lt;6; zz++) \/\/ entfernt den vorherigen Eingabeversuch\n{\nattempt&#91;zz]=0;\n}\n}\n\nvoid readKeypad()\n{\nchar key = keypad.getKey();\nif (key != NO_KEY)\n{\nswitch(key)\n{\ncase '*':\nz=0;\nbreak;\n\ncase '#':\ndelay(100); \/\/ zum Entprellen\ncheckPIN();\nbreak;\n\ndefault:\nattempt&#91;z]=key;\nz++;\n}\n}\n}\n\nvoid loop()\n{\nreadKeypad();\n}\n<\/code><\/pre>\n\n\n\n<p><strong>Wie geht es weiter?<\/strong><\/p>\n\n\n\n<p>Im n\u00e4chsten Artikel wird das Tastenfeld mit einer LED-Schaltung verbunden. Statt Infomeldungen im seriellen Monitor auszugeben, soll bei richtiger PIN eine gr\u00fcne LED leuchten und bei falscher PIN eine rote LED.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Es geht mit Tastenfeldern weiter und der Programmcode wird etwas angepasst\u2026<\/p>\n","protected":false},"author":1,"featured_media":48,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[22],"class_list":["post-1309","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino","tag-arduino-gruppe-peine"],"_links":{"self":[{"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/posts\/1309","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/comments?post=1309"}],"version-history":[{"count":3,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/posts\/1309\/revisions"}],"predecessor-version":[{"id":2788,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/posts\/1309\/revisions\/2788"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/media\/48"}],"wp:attachment":[{"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/media?parent=1309"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/categories?post=1309"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/tags?post=1309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}