Fórum témák

» Több friss téma
Fórum » Arduino
A klónok CH340 Soros-USB illesztőjének drivere (Letöltés)
Lapozás: OK   161 / 863
(#) atus1981 válasza morzsa15 hozzászólására (») Okt 23, 2015 /
 
Megoldódott, rossz helyre írtam a
  1. tft.reset();
  2.  tft.begin(0x9341);
sorokat.
Egyébként ebből indultam el:
  1. // IMPORTANT: Adafruit_TFTLCD LIBRARY MUST BE SPECIFICALLY
  2. // CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD.
  3. // SEE RELEVANT COMMENTS IN Adafruit_TFTLCD.h FOR SETUP.
  4.  
  5. #include <Adafruit_GFX.h>    // Core graphics library
  6. #include <Adafruit_TFTLCD.h> // Hardware-specific library
  7.  
  8. // The control pins for the LCD can be assigned to any digital or
  9. // analog pins...but we'll use the analog pins as this allows us to
  10. // double up the pins with the touch screen (see the TFT paint example).
  11. #define LCD_CS A3 // Chip Select goes to Analog 3
  12. #define LCD_CD A2 // Command/Data goes to Analog 2
  13. #define LCD_WR A1 // LCD Write goes to Analog 1
  14. #define LCD_RD A0 // LCD Read goes to Analog 0
  15.  
  16. #define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
  17.  
  18. // When using the BREAKOUT BOARD only, use these 8 data lines to the LCD:
  19. // For the Arduino Uno, Duemilanove, Diecimila, etc.:
  20. //   D0 connects to digital pin 8  (Notice these are
  21. //   D1 connects to digital pin 9   NOT in order!)
  22. //   D2 connects to digital pin 2
  23. //   D3 connects to digital pin 3
  24. //   D4 connects to digital pin 4
  25. //   D5 connects to digital pin 5
  26. //   D6 connects to digital pin 6
  27. //   D7 connects to digital pin 7
  28. // For the Arduino Mega, use digital pins 22 through 29
  29. // (on the 2-row header at the end of the board).
  30.  
  31. // Assign human-readable names to some common 16-bit color values:
  32. #define BLACK   0x0000
  33. #define BLUE    0x001F
  34. #define RED     0xF800
  35. #define GREEN   0x07E0
  36. #define CYAN    0x07FF
  37. #define MAGENTA 0xF81F
  38. #define YELLOW  0xFFE0
  39. #define WHITE   0xFFFF
  40.  
  41. Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
  42. // If using the shield, all control and data lines are fixed, and
  43. // a simpler declaration can optionally be used:
  44. // Adafruit_TFTLCD tft;
  45.  
  46. void setup(void) {
  47.   Serial.begin(9600);
  48.   Serial.println(F("TFT LCD test"));
  49.  
  50. #ifdef USE_ADAFRUIT_SHIELD_PINOUT
  51.   Serial.println(F("Using Adafruit 2.8\" TFT Arduino Shield Pinout"));
  52. #else
  53.   Serial.println(F("Using Adafruit 2.8\" TFT Breakout Board Pinout"));
  54. #endif
  55.  
  56.   Serial.print("TFT size is "); Serial.print(tft.width()); Serial.print("x"); Serial.println(tft.height());
  57.  
  58.   tft.reset();
  59.  
  60.   uint16_t identifier = tft.readID();
  61. identifier=0x9341;
  62.   if(identifier == 0x9325) {
  63.     Serial.println(F("Found ILI9325 LCD driver"));
  64.   } else if(identifier == 0x9328) {
  65.     Serial.println(F("Found ILI9328 LCD driver"));
  66.   } else if(identifier == 0x7575) {
  67.     Serial.println(F("Found HX8347G LCD driver"));
  68.   } else if(identifier == 0x9341) {
  69.     Serial.println(F("Found ILI9341 LCD driver"));
  70.   } else if(identifier == 0x8357) {
  71.     Serial.println(F("Found HX8357D LCD driver"));
  72.   } else {
  73.     Serial.print(F("Unknown LCD driver chip: "));
  74.     Serial.println(identifier, HEX);
  75.     Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
  76.     Serial.println(F("  #define USE_ADAFRUIT_SHIELD_PINOUT"));
  77.     Serial.println(F("should appear in the library header (Adafruit_TFT.h)."));
  78.     Serial.println(F("If using the breakout board, it should NOT be #defined!"));
  79.     Serial.println(F("Also if using the breakout, double-check that all wiring"));
  80.     Serial.println(F("matches the tutorial."));
  81.     return;
  82.   }
  83.  
  84.   tft.begin(identifier);
  85.  
  86.   Serial.println(F("Benchmark                Time (microseconds)"));
  87.  
  88.   Serial.print(F("Screen fill              "));
  89.   Serial.println(testFillScreen());
  90.   delay(500);
  91.  
  92.   Serial.print(F("Text                     "));
  93.   Serial.println(testText());
  94.   delay(3000);
  95.  
  96.   Serial.print(F("Lines                    "));
  97.   Serial.println(testLines(CYAN));
  98.   delay(500);
  99.  
  100.   Serial.print(F("Horiz/Vert Lines         "));
  101.   Serial.println(testFastLines(RED, BLUE));
  102.   delay(500);
  103.  
  104.   Serial.print(F("Rectangles (outline)     "));
  105.   Serial.println(testRects(GREEN));
  106.   delay(500);
  107.  
  108.   Serial.print(F("Rectangles (filled)      "));
  109.   Serial.println(testFilledRects(YELLOW, MAGENTA));
  110.   delay(500);
  111.  
  112.   Serial.print(F("Circles (filled)         "));
  113.   Serial.println(testFilledCircles(10, MAGENTA));
  114.  
  115.   Serial.print(F("Circles (outline)        "));
  116.   Serial.println(testCircles(10, WHITE));
  117.   delay(500);
  118.  
  119.   Serial.print(F("Triangles (outline)      "));
  120.   Serial.println(testTriangles());
  121.   delay(500);
  122.  
  123.   Serial.print(F("Triangles (filled)       "));
  124.   Serial.println(testFilledTriangles());
  125.   delay(500);
  126.  
  127.   Serial.print(F("Rounded rects (outline)  "));
  128.   Serial.println(testRoundRects());
  129.   delay(500);
  130.  
  131.   Serial.print(F("Rounded rects (filled)   "));
  132.   Serial.println(testFilledRoundRects());
  133.   delay(500);
  134.  
  135.   Serial.println(F("Done!"));
  136. }
  137.  
  138. void loop(void) {
  139.   for(uint8_t rotation=0; rotation<4; rotation++) {
  140.     tft.setRotation(rotation);
  141.     testText();
  142.     delay(2000);
  143.   }
  144. }
  145.  
  146. unsigned long testFillScreen() {
  147.   unsigned long start = micros();
  148.   tft.fillScreen(BLACK);
  149.   tft.fillScreen(RED);
  150.   tft.fillScreen(GREEN);
  151.   tft.fillScreen(BLUE);
  152.   tft.fillScreen(BLACK);
  153.   return micros() - start;
  154. }
  155.  
  156. unsigned long testText() {
  157.   tft.fillScreen(BLACK);
  158.   unsigned long start = micros();
  159.   tft.setCursor(0, 0);
  160.   tft.setTextColor(WHITE);  tft.setTextSize(1);
  161.   tft.println("Hello World!");
  162.   tft.setTextColor(YELLOW); tft.setTextSize(2);
  163.   tft.println(1234.56);
  164.   tft.setTextColor(RED);    tft.setTextSize(3);
  165.   tft.println(0xDEADBEEF, HEX);
  166.   tft.println();
  167.   tft.setTextColor(GREEN);
  168.   tft.setTextSize(5);
  169.   tft.println("Groop");
  170.   tft.setTextSize(2);
  171.   tft.println("I implore thee,");
  172.   tft.setTextSize(1);
  173.   tft.println("my foonting turlingdromes.");
  174.   tft.println("And hooptiously drangle me");
  175.   tft.println("with crinkly bindlewurdles,");
  176.   tft.println("Or I will rend thee");
  177.   tft.println("in the gobberwarts");
  178.   tft.println("with my blurglecruncheon,");
  179.   tft.println("see if I don't!");
  180.   return micros() - start;
  181. }
  182.  
  183. unsigned long testLines(uint16_t color) {
  184.   unsigned long start, t;
  185.   int           x1, y1, x2, y2,
  186.                 w = tft.width(),
  187.                 h = tft.height();
  188.  
  189.   tft.fillScreen(BLACK);
  190.  
  191.   x1 = y1 = 0;
  192.   y2    = h - 1;
  193.   start = micros();
  194.   for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  195.   x2    = w - 1;
  196.   for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  197.   t     = micros() - start; // fillScreen doesn't count against timing
  198.  
  199.   tft.fillScreen(BLACK);
  200.  
  201.   x1    = w - 1;
  202.   y1    = 0;
  203.   y2    = h - 1;
  204.   start = micros();
  205.   for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  206.   x2    = 0;
  207.   for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  208.   t    += micros() - start;
  209.  
  210.   tft.fillScreen(BLACK);
  211.  
  212.   x1    = 0;
  213.   y1    = h - 1;
  214.   y2    = 0;
  215.   start = micros();
  216.   for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  217.   x2    = w - 1;
  218.   for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  219.   t    += micros() - start;
  220.  
  221.   tft.fillScreen(BLACK);
  222.  
  223.   x1    = w - 1;
  224.   y1    = h - 1;
  225.   y2    = 0;
  226.   start = micros();
  227.   for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  228.   x2    = 0;
  229.   for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  230.  
  231.   return micros() - start;
  232. }
  233.  
  234. unsigned long testFastLines(uint16_t color1, uint16_t color2) {
  235.   unsigned long start;
  236.   int           x, y, w = tft.width(), h = tft.height();
  237.  
  238.   tft.fillScreen(BLACK);
  239.   start = micros();
  240.   for(y=0; y<h; y+=5) tft.drawFastHLine(0, y, w, color1);
  241.   for(x=0; x<w; x+=5) tft.drawFastVLine(x, 0, h, color2);
  242.  
  243.   return micros() - start;
  244. }
  245.  
  246. unsigned long testRects(uint16_t color) {
  247.   unsigned long start;
  248.   int           n, i, i2,
  249.                 cx = tft.width()  / 2,
  250.                 cy = tft.height() / 2;
  251.  
  252.   tft.fillScreen(BLACK);
  253.   n     = min(tft.width(), tft.height());
  254.   start = micros();
  255.   for(i=2; i<n; i+=6) {
  256.     i2 = i / 2;
  257.     tft.drawRect(cx-i2, cy-i2, i, i, color);
  258.   }
  259.  
  260.   return micros() - start;
  261. }
  262.  
  263. unsigned long testFilledRects(uint16_t color1, uint16_t color2) {
  264.   unsigned long start, t = 0;
  265.   int           n, i, i2,
  266.                 cx = tft.width()  / 2 - 1,
  267.                 cy = tft.height() / 2 - 1;
  268.  
  269.   tft.fillScreen(BLACK);
  270.   n = min(tft.width(), tft.height());
  271.   for(i=n; i>0; i-=6) {
  272.     i2    = i / 2;
  273.     start = micros();
  274.     tft.fillRect(cx-i2, cy-i2, i, i, color1);
  275.     t    += micros() - start;
  276.     // Outlines are not included in timing results
  277.     tft.drawRect(cx-i2, cy-i2, i, i, color2);
  278.   }
  279.  
  280.   return t;
  281. }
  282.  
  283. unsigned long testFilledCircles(uint8_t radius, uint16_t color) {
  284.   unsigned long start;
  285.   int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2;
  286.  
  287.   tft.fillScreen(BLACK);
  288.   start = micros();
  289.   for(x=radius; x<w; x+=r2) {
  290.     for(y=radius; y<h; y+=r2) {
  291.       tft.fillCircle(x, y, radius, color);
  292.     }
  293.   }
  294.  
  295.   return micros() - start;
  296. }
  297.  
  298. unsigned long testCircles(uint8_t radius, uint16_t color) {
  299.   unsigned long start;
  300.   int           x, y, r2 = radius * 2,
  301.                 w = tft.width()  + radius,
  302.                 h = tft.height() + radius;
  303.  
  304.   // Screen is not cleared for this one -- this is
  305.   // intentional and does not affect the reported time.
  306.   start = micros();
  307.   for(x=0; x<w; x+=r2) {
  308.     for(y=0; y<h; y+=r2) {
  309.       tft.drawCircle(x, y, radius, color);
  310.     }
  311.   }
  312.  
  313.   return micros() - start;
  314. }
  315.  
  316. unsigned long testTriangles() {
  317.   unsigned long start;
  318.   int           n, i, cx = tft.width()  / 2 - 1,
  319.                       cy = tft.height() / 2 - 1;
  320.  
  321.   tft.fillScreen(BLACK);
  322.   n     = min(cx, cy);
  323.   start = micros();
  324.   for(i=0; i<n; i+=5) {
  325.     tft.drawTriangle(
  326.       cx    , cy - i, // peak
  327.       cx - i, cy + i, // bottom left
  328.       cx + i, cy + i, // bottom right
  329.       tft.color565(0, 0, i));
  330.   }
  331.  
  332.   return micros() - start;
  333. }
  334.  
  335. unsigned long testFilledTriangles() {
  336.   unsigned long start, t = 0;
  337.   int           i, cx = tft.width()  / 2 - 1,
  338.                    cy = tft.height() / 2 - 1;
  339.  
  340.   tft.fillScreen(BLACK);
  341.   start = micros();
  342.   for(i=min(cx,cy); i>10; i-=5) {
  343.     start = micros();
  344.     tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
  345.       tft.color565(0, i, i));
  346.     t += micros() - start;
  347.     tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
  348.       tft.color565(i, i, 0));
  349.   }
  350.  
  351.   return t;
  352. }
  353.  
  354. unsigned long testRoundRects() {
  355.   unsigned long start;
  356.   int           w, i, i2,
  357.                 cx = tft.width()  / 2 - 1,
  358.                 cy = tft.height() / 2 - 1;
  359.  
  360.   tft.fillScreen(BLACK);
  361.   w     = min(tft.width(), tft.height());
  362.   start = micros();
  363.   for(i=0; i<w; i+=6) {
  364.     i2 = i / 2;
  365.     tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(i, 0, 0));
  366.   }
  367.  
  368.   return micros() - start;
  369. }
  370.  
  371. unsigned long testFilledRoundRects() {
  372.   unsigned long start;
  373.   int           i, i2,
  374.                 cx = tft.width()  / 2 - 1,
  375.                 cy = tft.height() / 2 - 1;
  376.  
  377.   tft.fillScreen(BLACK);
  378.   start = micros();
  379.   for(i=min(tft.width(), tft.height()); i>20; i-=6) {
  380.     i2 = i / 2;
  381.     tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0));
  382.   }
  383.  
  384.   return micros() - start;
  385. }
(#) morzsa15 válasza atus1981 hozzászólására (») Okt 23, 2015 /
 
Örülök neki hogy megy
(#) morzsa15 hozzászólása Okt 23, 2015 /
 
Na most a videón látható hiba jön elő hogy a második sort ha kikapcsolom valamiért vissza kapcsol. Szerintetek miért lehet ez? Videó
(#) morzsa15 hozzászólása Okt 23, 2015 /
 
Olyan kérdésem lenne hogy ilyen menürendszert hogyan lehetne csinálni kijelzőre? Ugye bár if-el ha úgy vizsgálom a panelt hiába törlöm ki az oldalt akkor is azt érzékeli ami az "előző" oldalt van. Hogyan lehetne ezt megoldani?
(#) cupika97 hozzászólása Okt 24, 2015 /
 
Tudna valaki segíteni, aki ért arduino programozásához? Aki tudna, és akar is segiteni, legyen szives irjon pm-et. Nagyon hálás lennék az biztos.
(#) ALI hozzászólása Okt 25, 2015 /
 
Sziasztok. Az mért van, hogy a temp magasabb vagy alacsonyabb mint a tempMin, tempMax
akkor az LCD-re 0 ír?
  1. if((temp >= tempMin) && (temp <= tempMax)) {
  2.        fanSpeed = map(temp, tempMin, tempMax, 32, 255);
  3.        fanLCD = map(temp, tempMin, tempMax, 10, 100);  
  4.        analogWrite(fan, fanSpeed);
(#) Kovidivi válasza ALI hozzászólására (») Okt 25, 2015 /
 
A map csinál érdekes dolgokat, utána tudsz nézni, hogy pontosan mit is. Helyettesítsd be az értékeket, és megtudod.
Egyébként módosítani kellene a map függvényt, hogy minimum ellenőrizze, hogy a bemenő adat a határokon belül van-e.
A hozzászólás módosítva: Okt 25, 2015
(#) jocoka hozzászólása Okt 25, 2015 /
 
Sziasztok
Egy kis induló segítség kéne van egy arduino nanom és most kezdtem vele ismerkedni de a következőt szeretném vele megvalósítani.
Egy ventilátor vezérlést ami úgy néz ki hogy van 2.db ventilátor 2.db nyomógomb ha az egyik nyomógombot megnyomom akkor a hozzá tartózó ventilátor megy a programba beállított ideig majd megáll ,a másik nyomógomb ugyan ezzel a szisztémával működjön,de most jön a csavar a dologban a ventilátorok maguktól is kapcsoljanak be x-óránként egy bizonyos meghatározott ideig.
Az időzítésnek pontosnak kellene lennie.
A dolog nem lesz megépítve csak tanulás véget találtam ki,mert már egyszer ezt én megépítettem élőbe avr-rel és azóta is remekül működnek,most csak az arduino programozása miatt érdekelne hogy hogy nézne ki egy ilyen program.
Az induló segítséget előre is köszönöm.
(#) Kovidivi válasza jocoka hozzászólására (») Okt 25, 2015 /
 
Az Arduinoban is egy AVR ketyeg, azt tudod?
(#) ALI válasza Kovidivi hozzászólására (») Okt 25, 2015 /
 
Meg lehet más módszerrel is csinálni ezt a szabályzást?
(#) Bell válasza ALI hozzászólására (») Okt 25, 2015 /
 
Nem adod meg mi történjen, ha temp < tempMin vagy ha temp > tempMax.
(#) ALI válasza Bell hozzászólására (») Okt 25, 2015 /
 
Ezt most nem értem mit akarsz mondani.
(#) jocoka válasza Kovidivi hozzászólására (») Okt 25, 2015 /
 
Szia
Igen tudom csak a program nyelvet akartam jobban érteni egy példán keresztül ezért írtam.
Üdv
(#) ALI válasza ALI hozzászólására (») Okt 25, 2015 /
 
Köszi közben le esett.
(#) Kera_Will válasza jocoka hozzászólására (») Okt 25, 2015 /
 
60 nap alatt arduinó tanfolyam .
Feliratkozol és meg kapod a napi / heti tanfolyami anyagot ...
Persze ASM , C elő ismeretekkel könnyebben értelmezheted a dolgokat.
Tavir-60nap
(#) atus1981 hozzászólása Okt 25, 2015 /
 
Sziasztok!
2 arduino nano-t szeretnék soros kommunikációval összekötni.
Az egyik végezné a méréseket és végrehajtaná a feladatokat (ez a rész már működik) és küldené a mért értékeket a másik nano-nak, ami egy kijelzőt hajtva megjelenítené. 5 méterre lenne a két eszköz egymástól. A soros adatátvitelre van valakinek példája, amiből elindulhatnék?
Köszi.
(#) icserny válasza atus1981 hozzászólására (») Okt 25, 2015 /
 
Célszerűbb lenne inkább két mini Pro kártyát összekötni (azokban nem zavarkodik ott fölöslegesen az USB-UART protokol konverter), amelyekben szabad az RX/TX kivezetés.

A soros átvitelre példaprogramokat a fejlesztői környezettel együtt települő mintapéldák "04. Communication" fejezetében találsz. Nyilván a vétel lesz az izgalmasabb feladat...
(#) atus1981 válasza icserny hozzászólására (») Okt 25, 2015 /
 
Értem, köszi!
Akkor ez jó lenne nekem?
Ha jól értem, akkor a csomagban benne van az Usb-Soros illesztő is a programozáshoz?
(#) Qju válasza atus1981 hozzászólására (») Okt 25, 2015 /
 
Ebben biztosan benne van az illesztő. Csak sajnos jövőre jönne meg.
A hozzászólás módosítva: Okt 25, 2015
(#) Kovidivi válasza atus1981 hozzászólására (») Okt 25, 2015 /
 
Nem hátrány a soros illesztő, le is lehet kötni, mindkettővel tökéletesen megoldható egy probléma. Hogy benne-e van-e az USB-soros illesztő, az le van írva az oldalon, ahol linkelted...
(#) icserny válasza atus1981 hozzászólására (») Okt 26, 2015 /
 
Csak akkor van benne az USB-soros illesztő, ha a lap alján kiválasztod opcióként (+3300 Ft-ért).
(#) andykaaa hozzászólása Okt 27, 2015 /
 
Sziasztok
Egy fordulatszammerot szeretnek megszerkeszteni hall erzekelovel, kb. ugy 1000 fordulat/perc-ig el kellene hogy merjen (kb. 18 fordulat/mp jelentene).
Az a kerdesem lenne honnan alljak neki a progi megirasanak. Milyen modon kellene megoldani az erzekelo kiolvasast adva a kb. 18 Hz maxim jel aradat.
Szivesen fogadok akarmilyen otletet. Koszonom.
A hozzászólás módosítva: Okt 27, 2015
(#) Bell válasza andykaaa hozzászólására (») Okt 27, 2015 /
 
Én megszakítással és microseconds()-al próbálnám. Az időből számítanám a fordulatszámot.
(#) andykaaa válasza Bell hozzászólására (») Okt 27, 2015 /
 
Ahogy szamolom az minim 55 milliszekundum (1000/18) lenne, ez igy ok lenne ?
A hozzászólás módosítva: Okt 27, 2015
(#) Bell válasza andykaaa hozzászólására (») Okt 27, 2015 /
 
Szerintem igen, az 55555 usec.
(#) Bell válasza andykaaa hozzászólására (») Okt 27, 2015 /
 
Célszerű lenne megmérni több fordulat idejét, azt kiszámolni, (esetleg átlagolni,) kijelezni, aztán kezdeni az elején.
(#) atus1981 válasza icserny hozzászólására (») Okt 27, 2015 /
 
Üdv!
Esetleg ha softwareserial-lal oldanám meg az adás-vételt? Akkor nincs ott a zavaró usb-soros illesztő....
(#) icserny válasza atus1981 hozzászólására (») Okt 27, 2015 /
 
Adatküldéshez jó és egyszerű megoldás a softwareserial, de a vételhez jobb a hardveres támogatás. Persze, ha az egyik eszközöd nem csinál semmi mást, csak várja, hogy mikor jön az adat, s utána kap egy szusszanásnyi időt, hogy azt feldolgozza, akkor a vétel is megoldható szoftveresen.
(#) saua hozzászólása Okt 27, 2015 /
 
Sziasztok,

Nyomógombbal és telefonról is lehet kapcsolgatni a LED –et, a telefon 100 miliszekundumonként lekérdezi a LED állapotát (küldi a 3-as karaktert és visszakapja az 1 vagy 0 karaktert). A telefonos applikáció AppInvetorral készült, azzal elboldogulok, hogy több lekérdező kódot küldjön és megjelenítse a választ, de hogyan lehetne 4 LED-re, 4 gombra bővíteniaz alábbi kódot ?

  1. /*
  2. LED attached from pin 12 to ground
  3.  pushbutton attached to pin 5 from +5V
  4. 10K resistor attached to pin 5 from ground
  5. */
  6. #include <SoftwareSerial.h>
  7.  
  8. int bluetoothTx = 2; // TX-O pin of bluetooth mate, Arduino D2
  9. int bluetoothRx = 3; // RX-I pin of bluetooth mate, Arduino D3
  10.  
  11. int led = 12;
  12. int button = 5;      
  13.  
  14. int dataFromBt;
  15.  
  16. SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
  17.  
  18. // változókat hozunk létre:
  19. int ledState = LOW;   // kimeneti pin aktuális állapota
  20. int buttonState;   // bemeneti pin aktuális állapota
  21. int lastButtonState = LOW;   // bemeneti pin előző értéke
  22.  
  23. long lastDebounceTime = 0;  
  24. long debounceDelay = 50;    
  25.  
  26. void setup()
  27. {
  28.  Serial.begin(9600); // Begin the serial monitor at 9600bps
  29.  
  30.  bluetooth.begin(115200); // The Bluetooth Mate defaults to 115200bps
  31.  bluetooth.print("$"); // Print three times individually
  32.  bluetooth.print("$");
  33.  bluetooth.print("$"); // Enter command mode
  34.  delay(100); // Short delay, wait for the Mate to send back CMD
  35.  bluetooth.println("U,9600,N"); // Temporarily Change the baudrate to 9600, no parity
  36.  // 115200 can be too fast at times for NewSoftSerial to relay the data reliably
  37.  bluetooth.begin(9600); // Start bluetooth serial at 9600
  38.  pinMode(led, OUTPUT);
  39.  pinMode(button, INPUT);
  40. digitalWrite(led, ledState);
  41. }
  42.  
  43. void loop()
  44. {
  45.  
  46. if(bluetooth.available()) // If the bluetooth sent any characters
  47.  {
  48. dataFromBt = bluetooth.read();
  49.  
  50.  if(dataFromBt == '1'){
  51. digitalWrite(led, HIGH);
  52. ledState = HIGH;
  53.  
  54.  }
  55.  if(dataFromBt == '0'){
  56. digitalWrite(led, LOW);
  57. ledState = LOW;
  58.  
  59.  }
  60. if(dataFromBt == '3'){
  61. bluetooth.print(ledState);
  62.  }
  63.  
  64.  }
  65.  
  66.   int reading = digitalRead(button);
  67.  
  68.   if (reading != lastButtonState) {
  69.     lastDebounceTime = millis();
  70.   }
  71.  
  72.   if ((millis() - lastDebounceTime) > debounceDelay) {
  73.     if (reading != buttonState) {
  74.       buttonState = reading;
  75.  
  76.       if (buttonState == HIGH) {
  77.         ledState = !ledState;
  78.         digitalWrite(led, ledState);
  79.       }
  80.      
  81.     }
  82.    
  83.   }
  84.  
  85.    lastButtonState = reading;
  86.  }
(#) atus1981 válasza icserny hozzászólására (») Okt 27, 2015 /
 
Megpróbálom azt a párosítást is.
Viszont csak egy sort jelenít meg az LCD.
Ez a küldő:
  1. void setup(){
  2.   Serial.begin(9600);
  3.  
  4. }
  5. void loop()   {
  6.   Serial.print("k");
  7.   Serial.print(analogRead(0));
  8.   Serial.print(" ");
  9.   Serial.print("pA");
  10.   Serial.print(analogRead(1));
  11.   Serial.print(" ");
  12.   Serial.print("pT");
  13.   Serial.print(analogRead(2));
  14.  
  15.   delay(1000);
  16. }

És ez a vevő:
  1. #include "LiquidCrystal.h";
  2. LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
  3.  
  4.  
  5. void setup(){
  6.      lcd.begin(16,2);
  7.  
  8.   Serial.begin(9600);
  9. }
  10. void loop() {
  11.  
  12.    
  13.  
  14.  
  15.   // when characters arrive over the serial port...
  16.   if (Serial.available()) {
  17.     // wait a bit for the entire message to arrive
  18.     delay(100);
  19.     // clear the screen
  20.     lcd.begin(16,2);
  21.     lcd.clear();
  22.     // read all the available characters
  23.     while (Serial.available() > 0) {
  24.       // display each character to the LCD
  25.      
  26.       lcd.write(Serial.read());
  27.     }
  28.   }
  29. }

Azt szeretném, hogy ha mind a két sorba tudnék írni.
Következő: »»   161 / 863
Bejelentkezés

Belépés

Hirdetés
XDT.hu
Az oldalon sütiket használunk a helyes működéshez. Bővebb információt az adatvédelmi szabályzatban olvashatsz. Megértettem