{"id":2945,"date":"2016-09-22T09:25:00","date_gmt":"2016-09-22T07:25:00","guid":{"rendered":"http:\/\/liceocuneo.it\/oddenino\/?p=2945"},"modified":"2016-09-22T09:33:14","modified_gmt":"2016-09-22T07:33:14","slug":"gestori-di-evento-in-nxt","status":"publish","type":"post","link":"https:\/\/liceocuneo.it\/oddenino\/gestori-di-evento-in-nxt\/","title":{"rendered":"Gestori di evento in NXT"},"content":{"rendered":"<p>Esercizio per casa: realizzare un programma che legga e visualizzi sulla prma riga il valore del sensore di luce mediante un ascoltatore di evento; rallentare l&#8217;esecuzione con una pausa di 1\/2 secondo.<\/p>\n<p><strong>1\u00ba metodo<\/strong><\/p>\n<pre>import lejos.nxt.Button;\r\nimport lejos.nxt.SensorPort;\r\nimport lejos.nxt.SensorPortListener;\r\nimport lejos.nxt.TouchSensor;\r\n\r\npublic class TouchSensorEvent {\r\n\t\r\n\tprivate TouchSensor ts;\r\n\t\r\n\tprivate class TouchSensorListener implements SensorPortListener {\r\n\r\n\t\t@Override\r\n\t\tpublic void stateChanged(SensorPort aSource, int aOldValue, int aNewValue) {\r\n\t\t\tSystem.out.println(aOldValue + \" =&gt; \" + aNewValue);\t\r\n\t\t}\r\n\t\t\r\n\t}\r\n\r\n\tpublic TouchSensorEvent() {\r\n\t\tts = new TouchSensor(SensorPort.S1);\r\n\t\tSensorPort.S1.addSensorPortListener(new TouchSensorListener());\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tnew TouchSensorEvent();\r\n\t\tButton.ESCAPE.waitForPressAndRelease();\r\n\t}\r\n\r\n}<\/pre>\n<p><strong>2\u00ba metodo<\/strong><\/p>\n<pre>import lejos.nxt.Button;\r\nimport lejos.nxt.SensorPort;\r\nimport lejos.nxt.SensorPortListener;\r\nimport lejos.nxt.TouchSensor;\r\n\r\npublic class TouchSensorEvent2 implements SensorPortListener {\r\n\r\n\tprivate TouchSensor ts;\r\n\r\n\t@Override\r\n\tpublic void stateChanged(SensorPort aSource, int aOldValue, int aNewValue) {\r\n\t\t\tSystem.out.println(aOldValue + \" =&gt; \" + aNewValue);\t\r\n\t}\r\n\r\n\tpublic TouchSensorEvent2() {\r\n\t\tts = new TouchSensor(SensorPort.S1);\r\n\t\tSensorPort.S1.addSensorPortListener(this);\r\n\t}\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tnew TouchSensorEvent2();\r\n\t\tButton.ESCAPE.waitForPressAndRelease();\r\n\t}\r\n\r\n}<\/pre>\n<p><strong>3\u00ba metodo<\/strong><\/p>\n<pre>import lejos.nxt.Button;\r\nimport lejos.nxt.SensorPort;\r\nimport lejos.nxt.SensorPortListener;\r\nimport lejos.nxt.TouchSensor;\r\n\r\npublic class TouchSensorEvent3 {\r\n\r\n\tprivate TouchSensor ts;\r\n\t\r\n\tpublic TouchSensorEvent3() {\r\n\t\tts = new TouchSensor(SensorPort.S1);\r\n\t\tSensorPort.S1.addSensorPortListener(new SensorPortListener() {\r\n\r\n\t\t\t@Override\r\n\t\t\tpublic void stateChanged(SensorPort aSource, int aOldValue, int aNewValue) {\r\n\t\t\tSystem.out.println(aOldValue + \" =&gt; \" + aNewValue);\t\r\n\t\t\t}\r\n\t\t\t\r\n\t\t} );\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tnew TouchSensorEvent3();\r\n\t\tButton.ESCAPE.waitForPressAndRelease();\r\n\t}\r\n\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Esercizio per casa: realizzare un programma che legga e visualizzi sulla prma riga il valore del sensore di luce mediante un ascoltatore di evento; rallentare l&#8217;esecuzione con una pausa di 1\/2 secondo. 1\u00ba metodo import lejos.nxt.Button; import lejos.nxt.SensorPort; import lejos.nxt.SensorPortListener; import lejos.nxt.TouchSensor; public class TouchSensorEvent { private TouchSensor ts; private class TouchSensorListener implements SensorPortListener { &hellip; <a href=\"https:\/\/liceocuneo.it\/oddenino\/gestori-di-evento-in-nxt\/\" class=\"more-link\">Continua a leggere <span class=\"screen-reader-text\">Gestori di evento in NXT<\/span><\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-2945","post","type-post","status-publish","format-standard","hentry","category-informatica"],"_links":{"self":[{"href":"https:\/\/liceocuneo.it\/oddenino\/wp-json\/wp\/v2\/posts\/2945","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/liceocuneo.it\/oddenino\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/liceocuneo.it\/oddenino\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/liceocuneo.it\/oddenino\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/liceocuneo.it\/oddenino\/wp-json\/wp\/v2\/comments?post=2945"}],"version-history":[{"count":0,"href":"https:\/\/liceocuneo.it\/oddenino\/wp-json\/wp\/v2\/posts\/2945\/revisions"}],"wp:attachment":[{"href":"https:\/\/liceocuneo.it\/oddenino\/wp-json\/wp\/v2\/media?parent=2945"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/liceocuneo.it\/oddenino\/wp-json\/wp\/v2\/categories?post=2945"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/liceocuneo.it\/oddenino\/wp-json\/wp\/v2\/tags?post=2945"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}