我正在尝试将整数转换为7位布尔二进制数组.到目前为止,代码不起作用:如果我输入说整数8要转换,而不是0001000我得到1000000,或者说15我应该得到0001111但我得到1111000.字符数组与二进制数组的长度不同这些立场是错误的.
public static void main(String[] args){
String maxAmpStr = Integer.toBinaryString(8);
char[] arr = maxAmpStr.toCharArray();
boolean[] binaryarray = new boolean[7];
for (int i=0; i<maxAmpStr.length(); i++){
if (arr[i] == '1'){
binaryarray[i] = true;
}
else if (arr[i] == '0'){
binaryarray[i] = false;
}
}
System.out.println(maxAmpStr);
System.out.println(binaryarray[0]);
System.out.println(binaryarray[1]);
System.out.println(binaryarray[2]);
System.out.println(binaryarray[3]);
System.out.println(binaryarray[4]);
System.out.println(binaryarray[5]);
System.out.println(binaryarray[6]);
}
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏.
是否可以以编程方式连接到蓝牙设备.因此,无需用户打开蓝牙设置并选择他们需要连接的设备.注意:它需要连接的设备将始终具有相同的设备名称.
所以我有一个带有以太网屏蔽的arduino,我目前使用浏览器url命令控制它,例如"192.168.2.1/digital/2/1"(数字引脚2变高),我想有一个android按钮请求该url没有在浏览器中打开它..是可能的,我该怎么办?
我在使用一些 arduino 代码时遇到问题。我使用我找到的以太网教程代码以及我找到的一些红外发射器和接收器代码,并且我尝试将它们结合起来。
http://www.ladyada.net/learn/sensors/ir.html
http://g33k.blogspot.com/2010/09/arduino-data-webserver-sample-web.html
两个代码本身都可以正常工作。
代码可以编译,但是当我调用以下 void IRDetector() 时,它不起作用。我已经对其进行了调试,到目前为止我发现当我使用变量 uint8_t 或 uint16_t 时(我尝试用整数和长整数替换它们)。我是否必须导入库才能使用 uint8_t ?有什么想法吗?
任何帮助,将不胜感激。
uint16_t pulses[100][2]; // pair is high and low pulse
uint8_t currentpulse = 0; // index for pulses we're storing
uint8_t highpulse, lowpulse; // temporary storage timing
void IRDetectCode(void)
{
while(true){
highpulse = lowpulse = 0; // start out with no pulse length
while (IRpin_PIN & (1 << IRpin)) {
// pin is still HIGH
// count off another few microseconds
highpulse++;
delayMicroseconds(RESOLUTION);
// …Run Code Online (Sandbox Code Playgroud)