<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="pl-pl">
<link rel="self" type="application/atom+xml" href="https://forum.atnel.pl/feed.php?f=47&amp;t=12902&amp;mode" />

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2015-09-10T17:22:18+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=47&amp;t=12902&amp;mode</id>
<entry>
<author><name><![CDATA[aska12]]></name></author>
<updated>2015-09-10T17:22:18+01:00</updated>
<published>2015-09-10T17:22:18+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=12902&amp;p=139484#p139484</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=12902&amp;p=139484#p139484"/>
<title type="html"><![CDATA[Dodawanie przycisków do sterowania z dwóch pozycji]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=12902&amp;p=139484#p139484"><![CDATA[
Witam udało mi się dodać do gotowego kodu sterowanie Expanderem z pozycji www teraz szukam jak dodać sterowania również z przycisków na impuls przycisk podłączony w sposób od GND do Pin (wejście)  Przycisk i do VCC<br />[syntax=c]#include &lt;OneWire.h&gt;<br />#include &lt;DallasTemperature.h&gt;<br />#include &lt;Ethernet.h&gt;<br />#include &lt;SPI.h&gt;<br />#include &lt;Wire.h&gt;<br />#include &lt;FastIO.h&gt;<br />#include &lt;I2CIO.h&gt;<br />#include &lt;LCD.h&gt;<br />#include &lt;LiquidCrystal.h&gt;<br />#include &lt;LiquidCrystal_I2C.h&gt;<br />#include &lt;LiquidCrystal_SR.h&gt;<br />#include &lt;LiquidCrystal_SR2W.h&gt;<br />#include &lt;LiquidCrystal_SR3W.h&gt;<br /><br /><br />#include &quot;Adafruit_MCP23017.h&quot;<br /><br />Adafruit_MCP23017 mcp;<br /><br /><br /><br /><br /><br />//termometr<br />#define ONE_WIRE_BUS 2<br />OneWire oneWire(ONE_WIRE_BUS);<br />DallasTemperature sensors(&amp;oneWire);<br />// lcd<br />LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Ustawienie adresu ukladu na 0x27<br /><br />//network NB: Pins 10, 11, 12 and 13 are reserved for Ethernet module.<br />byte mac&#91;&#93; = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };<br />byte ip&#91;&#93; = { 192, 168, 0, 177 };<br />byte gateway&#91;&#93; = { 192, 168, 1, 1 };<br />byte subnet&#91;&#93; = { 255, 255, 255, 0 };<br /><br />String readString;<br /><br /><br />String Led;<br /><br />int led&#91;&#93; = {00, 0, 1 , 2 , 3 , 4 , 5, 6, 7};<br />int numofleds = 8; //numofleds<br />String value&#91;&#93; = {&quot;on&quot;, &quot;on&quot;, &quot;on&quot;, &quot;on&quot;, &quot;on&quot;, &quot;on&quot;, &quot;on&quot;, &quot;on&quot;}; //startup all led are off<br />String value1&#91;&#93; = {&quot;1&quot;, &quot;1&quot;, &quot;1&quot;, &quot;1&quot;, &quot;1&quot;, &quot;1&quot;, &quot;1&quot;, &quot;1&quot;}; //startup all led are off<br />EthernetServer server(80);<br />String data;<br />void setup()<br />{<br />  lcd.begin(16, 2);  // Inicjalizacja LCD 2x16<br />  lcd.backlight(); // zalaczenie podwietlenia<br />  delay(500);<br />  lcd.setCursor(2, 0); // Ustawienie kursora w pozycji 0,0 (pierwszy wiersz, pierwsza kolumna)<br />  lcd.print(&quot;Control web end switch!&quot;);<br />  lcd.setCursor(1, 0); // Ustawienie kursora w pozycji 0,0 (pierwszy wiersz, pierwsza kolumna)<br />  delay(300);<br />  lcd.clear();<br />  lcd.setCursor(0, 0); // Ustawienie kursora w pozycji 0,0 (pierwszy wiersz, pierwsza kolumna)<br />  lcd.print(&quot;Temp:&quot;);<br />  // wyświetla temperaturę<br />  lcd.setCursor (11, 0);<br />  lcd.print(&quot;C&quot;);<br />  Serial.begin(9600);<br />  sensors.begin();<br />  // internt<br />  Ethernet.begin(mac, ip, gateway, subnet);<br />  server.begin();<br />  //set pin mode<br />  for (int j = 1; j &lt; (numofleds + 1); j++) {<br />    mcp.pinMode(led&#91;j&#93;, OUTPUT);<br />  }<br />  Serial.println(&quot;Serial READY&quot;);<br />  Serial.println(&quot;Ethernet READY&quot;);<br />  Serial.println(&quot;Server READY&quot;);<br />}<br /><br />void loop()<br />{<br />  sensors.requestTemperatures();<br />  EthernetClient client = server.available();<br /><br />  // wyświetla status<br />  lcd.setCursor (1, 1);<br />  lcd.print(value1&#91;1&#93;);<br />  lcd.setCursor (3, 1);<br />  lcd.print(value1&#91;2&#93;);<br />  lcd.setCursor (5, 1);<br />  lcd.print(value1&#91;3&#93;);<br />  lcd.setCursor (7, 1);<br />  lcd.print(value1&#91;4&#93;);<br />  lcd.setCursor (9, 1);<br />  lcd.print(value1&#91;5&#93;);<br />  lcd.setCursor (11, 1);<br />  lcd.print(value1&#91;6&#93;);<br />  lcd.setCursor (13, 1);<br />  lcd.print(value1&#91;7&#93;);<br />  lcd.setCursor (15, 1);<br />  lcd.print(value1&#91;8&#93;);<br />  lcd.setCursor (6, 0);<br />  lcd.print(sensors.getTempCByIndex(0));<br />  Serial.println(sensors.getTempCByIndex(0));<br />  delay(1);<br /><br /><br />  if (client) {<br />    // an http request ends with a blank line<br />    boolean current_line_is_blank = true;<br />    while (client.connected()) {<br />      if (client.available()) {<br />        char c = client.read();<br /><br />        if (readString.length() &lt; 100) {<br />          readString += c;<br />        }<br />        if (c == '\n' &amp;&amp; current_line_is_blank) {<br /><br />          client.println(&quot;HTTP/1.1 200 OK&quot;);<br />          client.println(&quot;Content-Type: text/html&quot;);<br />          client.println(&quot;Connection: close&quot;);  // the connection will be closed after completion of the response<br />          client.println(&quot;Refresh: 5&quot;);  // refresh the page automatically every 5 sec<br />          client.println();<br />          client.println(&quot;&lt;!DOCTYPE HTML&gt;&quot;);<br />          client.println(&quot;&lt;html&gt;&lt;head&gt;&quot;);<br />          client.println(&quot;&lt;style&gt;&quot;);<br />          client.println(&quot;body { color:red; }&quot;<br />                        );<br />          client.println(&quot;&lt;/style&gt;&quot;);<br />          client.println(&quot;&lt;/head&gt;&lt;body&gt;&lt;form method=get&gt;&quot;);<br />          client.println(&quot;&lt;p&gt;Led controller&lt;/p&gt;&quot;);<br /><br />          for (int i = 1; i &lt; (numofleds + 1) ; i++) {<br />            Led = String(&quot;led&quot;) + i;<br /><br />            if (readString.indexOf(Led + &quot;=on&quot;) &gt; 0 || readString.indexOf(&quot;all=on&quot;) &gt; 0) {<br />              Serial.println(Led + &quot;on&quot;);<br />              mcp.digitalWrite(led&#91;i&#93;, HIGH);<br />              value&#91;i&#93; = &quot;off&quot;;<br />              value1&#91;i&#93; = &quot;0&quot;;<br />            } else if (readString.indexOf(Led + &quot;=off&quot;) &gt; 0 || readString.indexOf(&quot;all=off&quot;) &gt; 0 ) {<br />              Serial.println(Led + &quot;off&quot;);<br />              mcp.digitalWrite(led&#91;i&#93;, LOW);<br />              value&#91;i&#93; = &quot;on&quot;;<br />              value1&#91;i&#93; = &quot;1&quot;;<br />            }<br /><br />            client.println(&quot;&lt;br&gt;&quot; + Led + &quot;  &lt;input type=submit name=&quot; + Led + &quot; value=&quot; + value&#91;i&#93; + &quot;&gt;&quot;);<br />          }<br /><br />          client.println(&quot;&lt;br&gt;All &lt;input type=submit name=all value=on&gt;&lt;input type=submit name=all value=off&gt;&quot;);<br /><br /><br /><br />          client.println(&quot;&lt;/from&gt;&lt;br /&gt;&lt;br /&gt;&quot;);<br />          // Print readings from sensors (DS18B20)<br />          client.println(&quot;Temperatura:  &quot;);<br />          client.print(sensors.getTempCByIndex(0));<br />          client.println(&quot;C&quot;);<br />          client.println(&quot;&lt;/html&gt;&lt;/body&gt;&quot;);<br />          break;<br />        }<br />        if (c == '\n') {<br />          // we're starting a new line<br />          current_line_is_blank = true;<br />        } else if (c != '\r') {<br />          // we've gotten a character on the current line<br />          current_line_is_blank = false;<br />        }<br />      }<br />    }<br />    // give the web browser time to receive the data<br />    delay(1);<br />    client.stop();<br />    readString = &quot;&quot;;<br /><br /><br /><br /><br /><br /><br />  }<br />}[/syntax]<br />piny są ta kolejne z Expandera mcp23017 8,9,10,11,12,13,14,15<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=3612">aska12</a> — 10 wrz 2015, o 17:22</p><hr />
]]></content>
</entry>
</feed>