www.elektronik.si Seznam forumov www.elektronik.si
Forum o elektrotehniki in računalništvu
 
 PomočPomoč  IščiIšči  Seznam članovSeznam članov  SkupineSkupine  StatisticsStatistika  AlbumAlbum  DatotekeFilemanager DokumentacijaDocDB LinksPovezave   Registriraj seRegistriraj se 
  PravilaPravila  LinksBolha  PriponkePriponke  KoledarKoledar  ZapiskiZapiski Tvoj profilTvoj profil Prijava za pregled zasebnih sporočilPrijava za pregled zasebnih sporočil PrijavaPrijava 

arduino napaka

 
Objavi novo temo   Odgovori na to temo   Printer-friendly version    www.elektronik.si Seznam forumov -> Arduino sekcija
Poglej prejšnjo temo :: Poglej naslednjo temo  
Avtor Sporočilo
sscott
Član
Član



Pridružen-a: Pet 10 Jul 2009 12:11
Prispevkov: 1133
Aktiv.: 6.30
Kraj: Medvode

PrispevekObjavljeno: Sob Apr 16, 2016 11:04 am    Naslov sporočila:  arduino napaka Odgovori s citatom

Rad bi naredil enostaven projekt, vendar mi povzroča težave. Sem popolnoma nov v arduino okolju. Tudi programirati se učim v bascomu, zato ne vem v čem je problem.

link do projekta
http://stonez56.blogspot.si/2014/09/arduino-android-led.html


Ko uvozim kodo v arduino mi javi napako

Light_RGB_LED was not declared in this scope

V čem je problem?
Nazaj na vrh
Odsoten Poglej uporabnikov profil Pošlji zasebno sporočilo
sscott
Član
Član



Pridružen-a: Pet 10 Jul 2009 12:11
Prispevkov: 1133
Aktiv.: 6.30
Kraj: Medvode

PrispevekObjavljeno: Sob Apr 16, 2016 11:04 am    Naslov sporočila:   Odgovori s citatom

Koda:
#include <SoftwareSerial.h>
#include <Wire.h>//Include libraries: SoftwareSerial & Wire
SoftwareSerial BT(11,12);
//Define PIN11 & PIN12 as RX and TX pins
 
//RGB LED Pins
int
 
PIN_RED = 3;
int
 
PIN_GREEN = 5;
int
 
PIN_BLUE = 6;
//RED LED at Pin 13
int
 
RED_LED = 13;
String RGB =
""
;
//store RGB code from BT
String RGB_Previous =
"255.255.255)"
;
//preserve previous RGB color for LED switch on/off, default White
String ON =
"ON"
;
//Check if ON command is received
String OFF =
"OFF"
;
//Check if OFF command is received
boolean RGB_Completed =
false
;
 
void
 
setup() {
 
Serial.begin(9600);
//Arduino serial port baud rate:9600
 
BT.begin(9600);
//My HC-05 module default baud rate is 9600
 
RGB.reserve(30);
 
 
pinMode(RED_LED, OUTPUT);
 
//Set pin13 as output for LED,
 
// this LED is on Arduino mini pro, not the RGB LED
}
 
void
 
loop() {
 
// put your main code here, to run repeatedly:
 
 
 
//Read each character from Serial Port(Bluetooth)
 
while
(BT.available()){
   
char
 
ReadChar = (
char
)BT.read();
 
   
// Right parentheses ) indicates complet of the string
   
if
(ReadChar ==
')'
){
     
RGB_Completed =
true
;
   
}
else
{
       
RGB += ReadChar;
   
}
 
}
 
 
 
//When a command code is received completely with ')' ending character
 
if
(RGB_Completed){
   
//Print out debug info at Serial output window
     
Serial.print(
"RGB:"
);
     
Serial.print(RGB);
     
Serial.print(
"     PreRGB:"
);
     
Serial.println(RGB_Previous);
     
 
     
if
(RGB==ON){
         
digitalWrite(13,HIGH);
         
RGB = RGB_Previous;
//We only receive 'ON', so get previous RGB color back to turn LED on
         
Light_RGB_LED();         
 
     
}
else
 
if
(RGB==OFF){
         
digitalWrite(13,LOW);
         
RGB =
"0.0.0)"
;
//Send OFF string to turn light off
         
Light_RGB_LED();
     
}
else
{
         
//Turn the color according the color code from Bluetooth Serial Port
         
Light_RGB_LED();   
         
RGB_Previous = RGB;     
     
}
     
//Reset RGB String 
 
     
RGB =
""
;
     
RGB_Completed =
false
;
     
 
   
 
 
}
//end if of check if RGB completed
 
 
}
// end of loop
 
void
 
Light_RGB_LED(){
 
 
int
 
SP1 = RGB.indexOf(
'.'
);
 
int
 
SP2 = RGB.indexOf(
'.'
, SP1+1);
 
int
 
SP3 = RGB.indexOf(
'.'
, SP2+1);
 
String R = RGB.substring(0, SP1);
 
String G = RGB.substring(SP1+1, SP2);
 
String B = RGB.substring(SP2+1, SP3);
 
 
//Print out debug info at Serial output window
 
Serial.print(
"R="
);
 
Serial.println( constrain(R.toInt(),0,255));
 
Serial.print(
"G="
);
 
Serial.println(constrain(G.toInt(),0,255));
 
Serial.print(
"B="
);
 
Serial.println( constrain(B.toInt(),0,255));
 
//Light up the LED with color code
 
//**2014-09-21
//Because these RGB LED are common anode (Common positive)
//So we need to take 255 to minus R,G,B value to get correct RGB color code
 
analogWrite(PIN_RED,  (255-R.toInt()));
 
analogWrite(PIN_GREEN, (255-G.toInt()));
 
analogWrite(PIN_BLUE,  (255-B.toInt()));
 
}
Nazaj na vrh
Odsoten Poglej uporabnikov profil Pošlji zasebno sporočilo
Jaka57
Moderator
Moderator



Pridružen-a: Ned 12 Dec 2004 21:47
Prispevkov: 5773
Aktiv.: 25.91
Kraj: Grosuplje

PrispevekObjavljeno: Sob Apr 16, 2016 4:44 pm    Naslov sporočila:   Odgovori s citatom

Ni mi jasno v čem bi bil problem, meni ga prevede brez problemov z verzijo Arduino 1.6.5
Koda:
#include <SoftwareSerial.h>
#include <Wire.h>//Include libraries: SoftwareSerial & Wire
SoftwareSerial BT(11,12); //Define PIN11 & PIN12 as RX and TX pins
 
//RGB LED Pins
int PIN_RED = 3;
int PIN_GREEN = 5;
int PIN_BLUE = 6;
//RED LED at Pin 13
int RED_LED = 13;
String RGB = "";
//store RGB code from BT
String RGB_Previous = "255.255.255)"; //preserve previous RGB color for LED switch on/off, default White
String ON = "ON"; //Check if ON command is received
String OFF = "OFF"; //Check if OFF command is received
boolean RGB_Completed = false;
 
void setup() {
 
Serial.begin(9600); //Arduino serial port baud rate:9600
BT.begin(9600);//My HC-05 module default baud rate is 9600
RGB.reserve(30);
pinMode(RED_LED, OUTPUT); //Set pin13 as output for LED,this LED is on Arduino mini pro, not the RGB LED
}
 
void loop() {// put your main code here, to run repeatedly:
//Read each character from Serial Port(Bluetooth)
 
while
(BT.available()){
   
char ReadChar = (char )BT.read();
 
   
// Right parentheses ) indicates complet of the string
   
if (ReadChar == ')'){
 RGB_Completed = true;
}
else
{
 RGB += ReadChar;
 }
 
}
 
 
 
//When a command code is received completely with ')' ending character
 
if(RGB_Completed){
   
//Print out debug info at Serial output window
     
Serial.print("RGB:");
Serial.print(RGB);
Serial.print("     PreRGB:");
Serial.println(RGB_Previous);

if (RGB==ON){
digitalWrite(13,HIGH);
RGB = RGB_Previous; //We only receive 'ON', so get previous RGB color back to turn LED on
Light_RGB_LED();         
}
else
 
if(RGB==OFF){
digitalWrite(13,LOW);
RGB = "0.0.0)"; //Send OFF string to turn light off
Light_RGB_LED();
}
else
{
Light_RGB_LED();  //Turn the color according the color code from Bluetooth Serial Port
RGB_Previous = RGB;     
}
RGB = "";//Reset RGB String 
RGB_Completed = false;
}
//end if of check if RGB completed
}
// end of loop
 
void Light_RGB_LED(){
int SP1 = RGB.indexOf('.');
int SP2 = RGB.indexOf('.', SP1+1);
int SP3 = RGB.indexOf('.', SP2+1);
String R = RGB.substring(0, SP1);
String G = RGB.substring(SP1+1, SP2);
String B = RGB.substring(SP2+1, SP3);
//Print out debug info at Serial output window
 
Serial.print("R=");
Serial.println( constrain(R.toInt(),0,255));
Serial.print("G=");
Serial.println(constrain(G.toInt(),0,255));
Serial.print("B=");
Serial.println( constrain(B.toInt(),0,255));
//Light up the LED with color code
 
//**2014-09-21
//Because these RGB LED are common anode (Common positive)
//So we need to take 255 to minus R,G,B value to get correct RGB color code
analogWrite(PIN_RED,  (255-R.toInt()));
analogWrite(PIN_GREEN, (255-G.toInt()));
analogWrite(PIN_BLUE,  (255-B.toInt()));
}


Slika prevoda:



LED_BT.JPG
 Opis:
 Velikost datoteke:  106.32 KB
 Pogledana:  15 krat

LED_BT.JPG



_________________
Lp, Jaka
Nazaj na vrh
Skrit Poglej uporabnikov profil Pošlji zasebno sporočilo
sscott
Član
Član



Pridružen-a: Pet 10 Jul 2009 12:11
Prispevkov: 1133
Aktiv.: 6.30
Kraj: Medvode

PrispevekObjavljeno: Sob Apr 16, 2016 9:46 pm    Naslov sporočila:   Odgovori s citatom

jaka hvala, tvojo kodo je prevedlo in uspešno naložilo na arduino mini.
Če dela bomo pa vidli jutri.

Kot vidim copy paste ne deluje. Je treba malo poznati programiranje arduinota Sad

Se ti ob priliki oddolžim. Sem večkrat v Grosupljah.

LP Mare
Nazaj na vrh
Odsoten Poglej uporabnikov profil Pošlji zasebno sporočilo
Pokaži sporočila:   
Objavi novo temo   Odgovori na to temo   Printer-friendly version    www.elektronik.si Seznam forumov -> Arduino sekcija Časovni pas GMT + 2 uri, srednjeevropski - poletni čas
Stran 1 od 1

 
Pojdi na:  
Ne, ne moreš dodajati novih tem v tem forumu
Ne, ne moreš odgovarjati na teme v tem forumu
Ne, ne moreš urejati svojih prispevkov v tem forumu
Ne, ne moreš brisati svojih prispevkov v tem forumu
Ne ne moreš glasovati v anketi v tem forumu
Ne, ne moreš pripeti datotek v tem forumu
Ne, ne moreš povleči datotek v tem forumu

Uptime: 70 dni


Powered by phpBB © 2001, 2005 phpBB Group