Showing posts with label read. Show all posts
Showing posts with label read. Show all posts
Tuesday, August 2, 2016
Arduino Genuino 101 example to read button and turn ON OFF LED
Arduino Genuino 101 example to read button and turn ON OFF LED

Simple example of Arduino/Genuino 101, to read button (on pin 6) and control LED (on pin 7) accodingly.
Connection:

_101_button_led.ino
/*
* Arduino/Genuino 101 example
* to read button and turn ON/OFF LED accordingly
*/
int LED = 7;
int BTN = 6;
void setup() {
pinMode(LED, OUTPUT);
pinMode(BTN, INPUT_PULLUP);
//indicate program start
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
delay(200);
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
}
void loop() {
digitalWrite(LED, !digitalRead(BTN));
delay(100);
}
Thursday, July 28, 2016
Arduino Mega read string from Serial display on 3 2 480 x 320 TFT LCD Shield
Arduino Mega read string from Serial display on 3 2 480 x 320 TFT LCD Shield

Arduino example run on Mega 2560, read string from Serial port, and display on 3.2" 480 x 320 TFT LCD Shield usin UTFT library. The sting is limited to 30 characters on each line.
Mega_UTFT_SerialRead.ino
/*
* Example run on Arduino Mega 2560 to read string from Serial,
* then display on 3.2" 480 x 320 TFT LCD Shield
*
* http://arduino-er.blogspot.com/search/label/3.2%22%20480%20x%20320%20TFT%20LCD%20Shield
*/
#include <UTFT.h>
extern uint8_t BigFont[];
UTFT myGLCD(CTE32HR,38,39,40,41);
const int NumOfRow = 20;
const int HeightOfRow = 16;
const int CharPerRow = 30;
String buffer[NumOfRow];
void setup()
{
Serial.begin(57600);
myGLCD.InitLCD();
myGLCD.clrScr();
myGLCD.setColor(255, 255, 255);
myGLCD.setBackColor(0, 0, 0);
myGLCD.setFont(BigFont);
myGLCD.print("Open Serial Monitor,", LEFT, 0);
myGLCD.print("to enter something.", LEFT, HeightOfRow);
initBuffer();
}
void loop()
{
String stringIn = Serial.readStringUntil( );
Serial.print(".");
if(!stringIn.equals("")){
Serial.print("*");
String stringToIns = stringIn.substring(0, CharPerRow);
insert(stringToIns);
Serial.println(stringToIns);
printBuffer();
}
}
void initBuffer(){
for(int i=0; i<NumOfRow; i++){
buffer[i] = "";
}
}
void insert(String ins){
for(int i=0; i<NumOfRow-1; i++){
buffer[i] = buffer[i+1];
}
buffer[NumOfRow-1] = ins;
}
void printBuffer(){
myGLCD.clrScr();
for(int i=0; i<NumOfRow; i++){
myGLCD.print(buffer[i], LEFT, i*HeightOfRow);
}
}
Subscribe to:
Posts (Atom)