Created
June 25, 2017 12:37
-
-
Save Dynamic-Gravity/1be0ac4e62acf54458f22184f510bc73 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* SS: pin 10 | |
* MOSI: pin 11 (NC) | |
* MISO: pin 12 | |
* SCK: pin 13 | |
* VCC: pin 14 | |
* GND: pin 15 | |
* arduino>>bluetooth | |
* RX: PIN 2 | |
* TX: PIN 3 | |
* Arduino Pro Mini 328 3.3V/8MHz | |
#include <SoftwareSerial.h>// import the serial library | |
#include "Adafruit_MAX31855.h" | |
#include <SPI.h> // Included here too due Arduino IDE; Used in above header | |
SoftwareSerial SoftSerial(3, 2); //arduino RX, TX | |
String BluetoothData; | |
#define RPin 5 | |
#define GPin 6 | |
#define BPin 9 | |
#define MAXCS 10 | |
Adafruit_MAX31855 thermocouple(MAXCS); | |
void setup() { | |
SoftSerial.begin(19200); | |
while (!Serial) { | |
delay(1); // wait for serial port to connect | |
} | |
pinMode(RPin, OUTPUT); | |
pinMode(GPin, OUTPUT); | |
pinMode(BPin, OUTPUT); | |
SoftSerial.println("Software serial over bluetooth starting...\n"); | |
} | |
void loop() { | |
delay(100); | |
if(SoftSerial.available()){ | |
BluetoothData = SoftSerial.readString(); | |
BluetoothData.trim(); | |
//SoftSerial.println(BluetoothData); | |
if(BluetoothData.equals("readAll")){ | |
SoftSerial.printf("Internal Temp = %10.0f",(float)thermocouple.readInternal()); | |
SoftSerial.printf("C = %10.0f",(float)thermocouple.readCelsius()); | |
SoftSerial.printf("F = %10.0f",(float)thermocouple.readFarenheit()); | |
} | |
else if(BluetoothData.equals("setLed")){ | |
int RedInt = 0; | |
int GreenInt = 0; | |
int BlueInt = 0; | |
float AlphaFloat = 0.0; | |
SoftSerial.println("send color like this: 255,255,255,1.0 "); | |
String RedStr = SoftSerial.readStringUntil(','); | |
Serial.read(); | |
String GreenStr = SoftSerial.readStringUntil(','); | |
Serial.read(); | |
String BlueStr = SoftSerial.readStringUntil(','); | |
Serial.read(); | |
String AlphaStr = SoftSerial.readStringUntil('\0'); | |
RedInt = RedStr.toInt(); | |
GreenInt = GreenStr.toInt(); | |
BlueInt = BlueStr.toInt(); | |
AlphaFloat = AlphaStr.toFloat(); | |
RedInt = constrain(RedInt, 0, 255); | |
GreenInt = constrain(GreenInt, 0, 255); | |
BlueInt = constrain(BlueInt, 0, 255); | |
AlphaFloat = constrain(AlphaFloat, 0.0, 1.0); | |
setLED(RedInt, GreenInt, BlueInt, AlphaFloat); | |
} | |
else if(BluetoothData.equals("readC")){ | |
SoftSerial.printf("C = %10.0f",(float)thermocouple.readCelsius()); | |
} | |
else if(BluetoothData.equals("readF")){ | |
SoftSerial.printf("F = %10.0f"(float)thermocouple.readFarenheit()); | |
} | |
else if(BluetoothData.equals("readInternal")){ | |
SoftSerial.printf("Internal Temp = %10.0f",(float)thermocouple.readInternal()); | |
} | |
else if(BluetoothData.equals("marco\n")){ | |
SoftSerial.printf("polo\n"); | |
} | |
else{ | |
SoftSerial.printf("I did not understand that\n"); | |
} | |
SoftSerial.printf("send: readAll, readInternal, readC, readF, marco\n"); | |
} | |
} | |
void setLED(int Red, int Green, int Blue, float Alpha ) | |
{ | |
//SoftSerial.println(Red); | |
//SoftSerial.println(Green); | |
//SoftSerial.println(Blue); | |
//SoftSerial.println(Alpha); | |
analogWrite(RPin, (Red * Alpha)); | |
analogWrite(GPin, (Green * Alpha)); | |
analogWrite(BPin, (Blue * Alpha)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment