dmx512 pico otg android app flutter demo source in the description
>> YOUR LINK HERE: ___ http://youtube.com/watch?v=5T75oIce2Kg
#dmx • #dmx512 • #pico • #flutter • replace GT with greater than symbol • replace LT with less than symbol • youtube don't like angle brackets • codes are shortened to fit youtube 5k limit • import 'dart:async'; • import '../widgets/app_bar.dart'; • import '../widgets/styles.dart'; • import '../widgets/button.dart'; • import '../utils/otg_arduino.dart'; • class DmxSpider extends StatelessWidget { • @override Widget build(BuildContext bc) {return Scaffold( • appBar: appBar('DMX spider demo'), • body: _buildBody());} • Widget _buildBody() { • final OtgArduino otg = Get.put(OtgArduino()); • return SingleChildScrollView( • child: Padding( • padding: const EdgeInsets.symmetric(vertical: 20), • child: Column(children: [ • Container(width: double.infinity, • child: GridView.count(primary: false, • crossAxisCount: 4, • shrinkWrap: true, • padding: EdgeInsets.all(8), • children: [ • • // 1st row • _buildcontent( • () =_GT_ otg.sendData(65), • Colors.red, • Icons.stop_sharp, • Colors.orangeAccent, • 'D', • Colors.orangeAccent), • Container(), • Container(), • • _buildcontent( • () =_GT_ otg.sendData(66), • Colors.white, • Icons.stop_sharp, • Colors.orangeAccent, • 'D', • Colors.orangeAccent), • // add more rows here • • SizedBox(height:15), • Obx(() =_GT_ Container( • child: otg.status != 'connected!' • ? button(otg.connect, 'pico connect') • : null)), • SizedBox(height:15), • ])));} • Widget _buildcontent(func, bgclr, icn, icnclr, txt, fntclr) { • return InkWell(onTap: func, child: Container( • margin: EdgeInsets.all(16), • decoration: BoxDecoration( • color: bgclr, • borderRadius: BorderRadius.all(Radius.circular(20))), • • child:(Center(child: CircleAvatar(radius:40, • backgroundColor: Colors.white, • child: Icon(icn, size:50) • // otg file • import 'dart:async'; • import 'dart:typed_data'; • import 'package:usb_serial/transaction.dart'; • import 'package:usb_serial/usb_serial.dart'; • class OtgArduino { • var _port; • RxString status = 'not connected'.obs; • RxString data = 'not connected'.obs; • StreamSubscription_LT_String_GT_? _su; • Transaction_GT_String_LT_? _tr; • void connect() async { • List_LT_UsbDevice_GT_ devices = await UsbSerial.listDevices(); • if ( devices.length == 0 ) {return;} • _port = await devices[0].create(); • • if (!await _port.open()) {return;} • • status.value = 'connected!'; • • await _port.setDTR(true); • await _port.setRTS(true); • await _port.setPortParameters( • 115200, UsbPort.DATABITS_8, UsbPort.STOPBITS_1, UsbPort.PARITY_NONE); • • _tr = Transaction.stringTerminated(_port!.inputStream as Stream_LT_Uint8List_GT_, Uint8List.fromList([13, 10])); • _su = _tr!.stream.listen((String line) { • data.value = line; • }); • } • void sendData(data) async { • await _port!.write(Uint8List.fromList([data]));}} • //arduino • #include LT_DmxOutput.h_GT • DmxOutput dmx; • #define UNIVERSE_LENGTH 512 • uint8_t universe[UNIVERSE_LENGTH + 1]; • char ch = 'X'; • bool rLe = false; • bool rRi = false; • bool gLe = false; • bool gRi = false; • bool bLe = false; • bool bRi = false; • bool wLe = false; • bool wRi = false; • void setup(){ • Serial.begin(115200); • dmx.begin(0); // gpio0 • for (int i = 1; i LT UNIVERSE_LENGTH + 1; i++) universe[i]=0; • // dimmer • universe[3] = 100; • dmx.write(universe, 512); • while (dmx.busy()); • } • void Color(int i, bool isOn) { • universe[i] = (isOn == true) ? 100 : 0; • dmx.write(universe, 512); • while (dmx.busy()); • } • void Motor(int i, int angle) { • universe[i] = angle; • dmx.write(universe,512); • while (dmx.busy());} • void loop() { • if (Serial.available()) { • ch = Serial.read(); • switch(ch){ • case 'A': rLe = !rLe; Color(12, rLe); break; • case 'B': wRi = !wRi; Color(8,wRi); break; • case 'C': gLe = !gLe; Color(11,gLe); break; • case 'D': bRi = !bRi; Color(7,bRi);break; • case 'E': bLe = !bLe; Color(10,bLe); break; • case 'F': gRi = !gRi; Color(6,gRi); break; • case 'G': wLe = !wLe; Color(9,wLe); break; • case 'H': rRi = !rRi; Color(5,rRi); break; • case 'I': Motor(1,30); break; • case 'J': Motor(1,250); break; • case 'K': Motor(2,250); break; • case 'L': Motor(2,30); break; • } • } else { • switch(ch){ • case 'A': Color(12, rLe); break; • case 'B': Color(8, wRi); break; • case 'C': Color(11,gLe); break; • case 'D': Color(7,bRi);break; • case 'E': Color(10,bLe); break; • case 'F': Color(6,gRi); break; • case 'G': Color(9,wLe); break; • case 'H': Color(5,rRi); break; • case 'I': Motor(1,30); break; • case 'J': Motor(1,250); break; • case 'K': Motor(2,250); break; • case 'L': Motor(2,30); break; • }}delay(10);}
#############################