<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.pessinurmi.com/index.php?action=history&amp;feed=atom&amp;title=L%C3%A4hettimen_l%C3%A4hdekoodi_v1</id>
	<title>Lähettimen lähdekoodi v1 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.pessinurmi.com/index.php?action=history&amp;feed=atom&amp;title=L%C3%A4hettimen_l%C3%A4hdekoodi_v1"/>
	<link rel="alternate" type="text/html" href="https://wiki.pessinurmi.com/index.php?title=L%C3%A4hettimen_l%C3%A4hdekoodi_v1&amp;action=history"/>
	<updated>2026-06-06T10:49:57Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://wiki.pessinurmi.com/index.php?title=L%C3%A4hettimen_l%C3%A4hdekoodi_v1&amp;diff=758&amp;oldid=prev</id>
		<title>Exf: Created page with &quot;Lähettimen lähdekoodi V1&lt;syntaxhighlight lang=&quot;c#&quot;&gt; #include &lt;RH_ASK.h&gt; #include &lt;SPI.h&gt;  RH_ASK driver(1000); #define TX_PIN 12  #define DIP1 2 #define DIP2 3 #define DIP3 4 #define DIP4 5  byte crc8_dallas(const String &amp;data) {   byte crc = 0x00;   for (int i = 0; i &lt; data.length(); i++) {     crc ^= data[i];     for (int j = 0; j &lt; 8; j++) {       crc = (crc &amp; 0x80) ? (crc &lt;&lt; 1) ^ 0x31 : (crc &lt;&lt; 1);     }   }   return crc; }  void setup() {   driver.init();   pinMod...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.pessinurmi.com/index.php?title=L%C3%A4hettimen_l%C3%A4hdekoodi_v1&amp;diff=758&amp;oldid=prev"/>
		<updated>2025-10-03T14:35:39Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;Lähettimen lähdekoodi V1&amp;lt;syntaxhighlight lang=&amp;quot;c#&amp;quot;&amp;gt; #include &amp;lt;RH_ASK.h&amp;gt; #include &amp;lt;SPI.h&amp;gt;  RH_ASK driver(1000); #define TX_PIN 12  #define DIP1 2 #define DIP2 3 #define DIP3 4 #define DIP4 5  byte crc8_dallas(const String &amp;amp;data) {   byte crc = 0x00;   for (int i = 0; i &amp;lt; data.length(); i++) {     crc ^= data[i];     for (int j = 0; j &amp;lt; 8; j++) {       crc = (crc &amp;amp; 0x80) ? (crc &amp;lt;&amp;lt; 1) ^ 0x31 : (crc &amp;lt;&amp;lt; 1);     }   }   return crc; }  void setup() {   driver.init();   pinMod...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Lähettimen lähdekoodi V1&amp;lt;syntaxhighlight lang=&amp;quot;c#&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;RH_ASK.h&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RH_ASK driver(1000);&lt;br /&gt;
#define TX_PIN 12&lt;br /&gt;
&lt;br /&gt;
#define DIP1 2&lt;br /&gt;
#define DIP2 3&lt;br /&gt;
#define DIP3 4&lt;br /&gt;
#define DIP4 5&lt;br /&gt;
&lt;br /&gt;
byte crc8_dallas(const String &amp;amp;data) {&lt;br /&gt;
  byte crc = 0x00;&lt;br /&gt;
  for (int i = 0; i &amp;lt; data.length(); i++) {&lt;br /&gt;
    crc ^= data[i];&lt;br /&gt;
    for (int j = 0; j &amp;lt; 8; j++) {&lt;br /&gt;
      crc = (crc &amp;amp; 0x80) ? (crc &amp;lt;&amp;lt; 1) ^ 0x31 : (crc &amp;lt;&amp;lt; 1);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  return crc;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
  driver.init();&lt;br /&gt;
  pinMode(DIP1, INPUT_PULLUP);&lt;br /&gt;
  pinMode(DIP2, INPUT_PULLUP);&lt;br /&gt;
  pinMode(DIP3, INPUT_PULLUP);&lt;br /&gt;
  pinMode(DIP4, INPUT_PULLUP);&lt;br /&gt;
  pinMode(TX_PIN, OUTPUT);&lt;br /&gt;
  randomSeed(analogRead(0));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
String readDipCode() {&lt;br /&gt;
  String code = &amp;quot;&amp;quot;;&lt;br /&gt;
  code += (digitalRead(DIP1) == LOW) ? &amp;#039;1&amp;#039; : &amp;#039;0&amp;#039;;&lt;br /&gt;
  code += (digitalRead(DIP2) == LOW) ? &amp;#039;1&amp;#039; : &amp;#039;0&amp;#039;;&lt;br /&gt;
  code += (digitalRead(DIP3) == LOW) ? &amp;#039;1&amp;#039; : &amp;#039;0&amp;#039;;&lt;br /&gt;
  code += (digitalRead(DIP4) == LOW) ? &amp;#039;1&amp;#039; : &amp;#039;0&amp;#039;;&lt;br /&gt;
  return code;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void loop() {&lt;br /&gt;
  String code = readDipCode();&lt;br /&gt;
  String core = &amp;quot;S&amp;quot; + code + &amp;quot;E&amp;quot;;&lt;br /&gt;
  byte crc = crc8_dallas(core);&lt;br /&gt;
  String message = core + String(crc, HEX);&lt;br /&gt;
&lt;br /&gt;
  driver.send((uint8_t*)message.c_str(), message.length());&lt;br /&gt;
  driver.waitPacketSent();&lt;br /&gt;
&lt;br /&gt;
  delay(random(800, 1800));  // satunnainen lähetysväli&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Exf</name></author>
	</entry>
</feed>