Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <EEPROM.h>
- //Variáveis do Projeto
- int Ans1,Ans2,Ans3,Ans4,Ans5,Ans6,Ans7,Ans8,Ans9;
- int x ;
- char buffer[18];
- //Prototipação das funções
- void splitString(char* data);
- void setLED(char* data);
- void setup(){
- Serial.begin(9600);
- pinMode(3,OUTPUT);
- pinMode(5,OUTPUT);
- pinMode(6,OUTPUT);
- pinMode(9,OUTPUT);
- pinMode(10,OUTPUT);
- pinMode(11,OUTPUT);
- pinMode(13,OUTPUT);
- //Para ler na inicialização
- x = EEPROM.read(0);
- Serial.print("Valor lido ");
- Serial.println(x);
- }
- void loop()
- {
- if (Serial.available() > 0) {
- int index=0;
- delay(100); // permite o buffer encher
- int numChar = Serial.available();
- }
- if (numChar>15) {
- numChar=15;
- }
- while (numChar--) {
- buffer[index++] = Serial.read();
- }
- splitString(buffer);
- }
- //Subrotinas do projeto prototipar na declaração
- //da seguinte maneira tipo nomeFuncao (parametros);
- void splitString(char* data) {
- char* parameter;
- parameter = strtok (data, " ,");
- while (parameter != NULL) {
- setLED(parameter);
- parameter = strtok (NULL, " ,");
- }
- // Limpa os textos e o buffer serial
- for (int x=0; x<16; x++) {
- buffer[x]='\0';
- }
- Serial.flush();
- }
- void setLED(char* data) {
- int Ans1,Ans2,Ans3,Ans4,Ans5,Ans6,Ans7,Ans8,Ans9;
- if (data[0] == 'a') {
- Ans1 = strtol(data+1, NULL, 10);
- Ans1 = constrain(Ans1,0,9999);
- }
- if (data[0] == 'b') {
- Ans2 = strtol(data+1, NULL, 10);
- Ans2 = constrain(Ans2,0,9999);
- }
- if (data[0] == 'c') {
- int Ans3 = strtol(data+1, NULL, 10);
- Ans3 = constrain(Ans3,0,9999);
- }
- if (data[0] == 'd') {
- Ans4 = strtol(data+1, NULL, 10);
- Ans4 = constrain(Ans4,0,255);
- analogWrite(3, Ans4);
- }
- if (data[0] == 'e') {
- Ans5 = strtol(data+1, NULL, 10);
- Ans5 = constrain(Ans5,0,255);
- analogWrite(5, Ans5);
- }
- if (data[0] == 'f') {
- Ans6 = strtol(data+1, NULL, 10);
- Ans6 = constrain(Ans6,0,255);
- analogWrite(6, Ans6);
- }
- if (data[0] == 'g') {
- Ans7 = strtol(data+1, NULL, 10);
- Ans7 = constrain(Ans7,0,255);
- analogWrite(9, Ans7);
- }
- if (data[0] == 'h') {
- Ans8 = strtol(data+1, NULL, 10);
- Ans8 = constrain(Ans8,0,255);
- analogWrite(10, Ans8);
- }
- if (data[0] == 'i') {
- x = EEPROM.read(0);
- Ans9 = strtol(data+1, NULL, 10);
- Ans9 = constrain(Ans9,0,255);
- x = Ans9;
- EEPROM.write(0,x);
- analogWrite(11, x);
- Serial.println(x);
- }
- if(Ans9 == 255){
- digitalWrite(13,HIGH);
- }
- if(data[0] == 'x'){
- digitalWrite(13,LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement