Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import processing.serial.*;
- import java.io.*;
- import java.net.*;
- Serial myPort;
- String inString = "null";
- // the MLabel object // http://pastebin.com/M3eLpVMQ
- MLabel l1;
- MLabel status;
- // the MLabel object // http://pastebin.com/M3eLpVMQ
- int value = 0;
- void setup(){
- size(450, 600);
- myPort = new Serial(this, "COM9", 9600);
- myPort.bufferUntil('\n');
- l1 = new MLabel("", 170, 200, 40, 120, 60, 20);
- status = new MLabel("st", 200, 80, 40, 120, 60, 20);
- frameRate(60);
- }
- void draw(){
- background(39,174,96,255);
- l1.render();
- status.render();
- //l1.setText("B8E7B4FE");
- status.setText(Integer.toString(value));
- }
- void serialEvent(Serial p) {
- String inString2 = p.readStringUntil('\n');
- if ( check(inString2, "F0B4BB43") || check(inString2, "37F4421F") || check(inString2,"E49BBA9A") ){
- value++;
- myPort.write(1);
- }else if ( check(inString2, "45481702") || check(inString2, "765542FB") || check(inString2,"30C7A2FF") ){
- value--;
- myPort.write(2);
- }
- if ( check(inString2, "B8E7B4FE") ){
- String s = get("sendMessage?chat_id=121414901&text=" + Integer.toString(value));
- if ( s.contains("\"ok\":true") ){
- Thread t = new Thread(
- new Runnable(){
- public void run(){
- l1.setText("sent");
- myPort.write(10);
- try{ Thread.sleep(1000); }catch(Exception ex){}
- l1.setText(" ");
- }
- }
- );
- t.start();
- }
- }
- inString = inString2;
- println(inString);
- }
- boolean check(String s, String code){
- if ( s.contains(code) ) return true; return false;
- }
- public String get(String method){
- String inputLine = null;
- try {
- URL http = new URL("https://api.telegram.org/bot" + "Your bot token" +"/" + method);
- URLConnection con = http.openConnection();
- BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
- while ((inputLine = in.readLine()) != null)
- return inputLine;
- in.close();
- } catch (Exception e) {}
- return inputLine;
- }
Add Comment
Please, Sign In to add comment