Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
The file that is currently on an Arduino Uno with a serial number of 85235333035351C01100
/*
USE_GITHUB_USERNAME=dewomser
Arduinino Box with several Outputs Contrlerd by Serial Bus
RGB LED
Relais
Sound
Remote 433MHz
Serial input is 6 Numbers Example, comma seperated: 0-255,0-255,0-255,0-1,0-1,0-1
(color1,color2,color3,relais,musik,remote)
I use public Domain
created by Stefan Höhn Feb.2016
---------
Reading a serial ASCII-encoded string.
This sketch demonstrates the Serial parseInt() function.
It looks for an ASCII string of comma-separated values.
It parses them into ints, and uses those to fade an RGB LED.
Circuit: Common-anode RGB LED wired like so:
* Red cathode: digital pin 3
* Green cathode: digital pin 5
* blue cathode: digital pin 6
* anode: +5V
created 13 Apr 2012
by Tom Igoe
This example code is in the public domain.
*/
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
//Lautsprecher Ausgabe kommt vom Programm Melodie
// in dieSerialle
// Eingabe muss sowas rein 0,0,0,0,0
// Bedeudet Farbe,Farbe,Farbe,Relais,Musik
int ledPin = 13;
int speakerOut = 9;
byte names[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'};
int tones[] = {1915, 1700, 1519, 1432, 1275, 1136, 1014, 956};
byte melody[] = "2d2a1f2c2d2a2d2c2f2d2a2c2d2a1f2c2d2a2a2g2p8p8p8p";
// count length: 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
// 10 20 30
int count = 0;
int count2 = 0;
int count3 = 0;
int MAX_COUNT = 24;
int statePin = LOW;
int musik = LOW;
int remote =LOW;
// pins for the LEDs:
const int redPin = 3;
const int greenPin = 5;
const int bluePin = 6;
const int relaisPin =2;
void setup() {
// initialize serial:
// Transmitter is connected to Arduino Pin #10
mySwitch.enableTransmit(4);
// Optional set pulse length.
// mySwitch.setPulseLength(320);
Serial.begin(9600);
// make the pins outputs:
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(relaisPin,OUTPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
// if there's any serial available, read it:
while (Serial.available() > 0) {
// look for the next valid integer in the incoming serial stream:
int red = Serial.parseInt();
// do it again:
int green = Serial.parseInt();
// do it again:
int blue = Serial.parseInt();
// do it again:
int relais=Serial.parseInt();
// do it again:
int musik=Serial.parseInt();
// do it again:
int remote=Serial.parseInt();
// look for the newline. That's the end of your
// sentence:
if (Serial.read() == '\n') {
// constrain the values to 0 - 255 and invert
// if you're using a common-cathode LED, just use "constrain(color, 0, 255);"
red = 255 - constrain(red, 0, 255);
green = 255 - constrain(green, 0, 255);
blue = 255 - constrain(blue, 0, 255);
relais = 0 - constrain (relais, 0, 1);
musik = LOW - constrain (musik, LOW, HIGH);
remote = LOW - constrain (remote, LOW ,HIGH);
// fade the red, green, and blue legs of the LED:
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
digitalWrite(relaisPin, relais);
// print the three numbers in one string as hexadecimal:
Serial.print(red, HEX);
Serial.print(green, HEX);
Serial.println(blue, HEX);
Serial.println(musik, HEX);
if (musik) {
analogWrite(speakerOut, 0);
for (count = 0; count < MAX_COUNT; count++) {
statePin = !statePin;
digitalWrite(ledPin, statePin);
for (count3 = 0; count3 <= (melody[count*2] - 48) * 30; count3++) {
for (count2=0;count2<8;count2++) {
if (names[count2] == melody[count*2 + 1]) {
analogWrite(speakerOut,500);
delayMicroseconds(tones[count2]);
analogWrite(speakerOut, 0);
delayMicroseconds(tones[count2]);
}
if (melody[count*2 + 1] == 'p') {
// make a pause of a certain size
analogWrite(speakerOut, 0);
delayMicroseconds(500);
musik = LOW;
}
}
}
}
}
if (remote) {
// Switch on:
// The first parameter represents the familycode (a, b, c, ... f)
// The second parameter represents the group number
// The third parameter represents the device number
//
// In this example it's family 'b', group #3, device #2
mySwitch.switchOn('c', 1, 1);
// Wait a second
// delay(1000);
// Switch off
// mySwitch.switchOff('b', 3, 2);
// Wait another second
//delay(1000);
}
else
{
mySwitch.switchOff('c', 1, 1);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment