I made a project Led on/offbut with 5 leds. I send strings to arduino bluetooth for on or off leds. But i need led on only some leds. For example i wont led on pin 10 and pin 9. But Before on pin 12 i can't on pin 11, and before off pin 12 i can't off another pins? Why? I put my code here:
For arduino:
while(Serial.available() > 0)
{
command = ((byte)Serial.read());
if(command == ':')
{
break;
}
else
{
string += command;
}
delay(1);
}
if(string == "A")
{
ledOn();// ledOn(){analogWrite(led, 255); delay(10);}
}
if(string =="B")
{
ledOff();
}
if(string == "C")
{
ledOnB();
}
if(string =="D")
{
ledOffB();
}
if(string == "E")
{
ledOnC();
}
if(string =="F")
{
ledOffC();
}
if(string =="G")
{
ledOnD();
}
if(string =="H")
{
ledOffD();
}
if(string == "I")
{
ledOnE();
}
if(string =="J")
{
ledOffE();
}
Related
if (buttonClicked.contains(1) && buttonClicked.contains(2)) {
if (playerOneLastClicked) {
imgViewBackground1.setImageResource(R.drawable.rca)
} else {
imgViewBackground1.setImageResource(R.drawable.wac)
}
}
if (buttonClicked.contains(3) && buttonClicked.contains(4) && buttonClicked.contains(5)) {
if (playerOneLastClicked) {
imgViewBackground2.setImageResource(R.drawable.rca)
} else {
imgViewBackground4.setImageResource(R.drawable.wac)
}
}
when player1 or player2 last click in (buttonClicked.contains(1) && buttonClicked.contains(2)) imgViewBackgound1 change but when the players click button 3,4 or 5 imgViewBackground keep changing.
I want when imgViewBackground1 take (R.drawable.rca) or (R.drawable.wac) don't change any more.
If imgViewBackground is not going to have an imageview you could just add an extra check e.g.
if (imgViewBackground1.drawable == null) {
if (playerOneLastClicked) {
imgViewBackground1.setImageResource(R.drawable.rca)
} else {
imgViewBackground1.setImageResource(R.drawable.wac)
}
}
}
or if it would have an imageview already and you don't want it set again
if (imgViewBackground1.drawable != resources.getDrawable(R.drawable.rcs, null)
|| imgViewBackground1.drawable != resources.getDrawable(R.drawable.wac, null))
if (playerOneLastClicked) {
imgViewBackground1.setImageResource(R.drawable.rca)
} else {
imgViewBackground1.setImageResource(R.drawable.wac)
}
}
}
I posted something else about this a while ago. Basically, I was trying to establish a Bluetooth connection between an Android phone and an Arduino. This was to get a remote control car working wirelessly.
I decided to get an HC-06 Bluetooth module instead of the HC-08 I had. This seemed to work for part of it. I can send a string from an Android phone to an Arduino but nothing happens. When testing this I have my Arduino hooked up to my computer and have the serial monitor displayed. When I send the string, the Arduino receives this string then activates a certain piece of code. The forward code works and has a serial print line in it, and when the certain string is sent the word forward is printed on the serial monitor. So I know it's being received but it's just not activating the other part of the function for some reason.
Can anybody help?
I'm pretty sure it's the Arduino code so here it is:
if (Serial.available() > 0) {
string = "";
}
while (Serial.available() > 0) {
command = ((byte)Serial.read());
if (command == ':') {
break;
} else {
string += command;
}
delay(1);
}
if (string == "F") {
forward();
}
if (string == "B") {
back();
}
if (string == "R") {
right();
}
if (string == "L") {
left();
}
if (string == "S") {
stop();
}
}
void forward() {
digitalWrite(ENA, HIGH);
digitalWrite(ENB, HIGH);
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
Serial.println("Forward");
}
Let's try this, just remove
if (Serial.available() > 0) {
string = "";
}
And add string = ""; after each cases.
Result : Hope that will help you
while (Serial.available() > 0) {
command = ((byte)Serial.read());
if (command == ':') {
break;
} else {
string += command;
}
delay(1);
}
if (string == "F") {
forward();
string = "";
}
if (string == "B") {
back();
string = "";
}
if (string == "R") {
right();
string = "";
}
if (string == "L") {
left();
string = "";
}
if (string == "S") {
stop();
string = "";
}
}
I created registration screen i want to disable submit button and it should enable only when all the fields get correct input, bellow i added list of text fields these fields must get correct input and submit button must enable.
protected boolean validateData() {
if (email.getText().toString().trim().length() == 0) {
email.setError("Email-ID/Registered Number can not be empty!");
return false;
} else if (!(email.getText().toString().trim().contains("#"))
&& email.getText().toString().trim().length() < 10) {
email.setError("Email/Registered Number not valid!");
return false;
} else if (!(email.getText().toString().trim().contains("."))
&& email.getText().toString().trim().length() < 10) {
email.setError("Email/Registered Number not valid!");
return false;
}
else if (!(email.getText().toString().trim().contains("#"))
&& !(email.getText().toString().trim().contains("."))
&& email.getText().toString().trim().length() > 10) {
email.setError("Email/Registered Number not valid!");
return false;
}
else if (email.getText().toString().trim().contains("#")
|| email.getText().toString().trim().contains(".")) {
if (!WebServiceSingleTon.getInstance().isEmailValid(
email.getText().toString().trim())) {
email.setError("Email is not valid!");
return false;
} else if (password.getText().toString().trim().length() == 0) {
password.setError("password can not be empty!");
return false;
} else if (password.getText().toString().trim().length() < 6) {
password.setError("Your password need to have minimum 6 characters!");
return false;
} else if (password.getText().toString().trim().length() > 20) {
password.setError("Your password need to have maximum 20 characters!");
return false;
}
} else if (password.getText().toString().trim().length() == 0) {
password.setError("password can not be empty!");
return false;
} else if (password.getText().toString().trim().length() < 6) {
password.setError("Your password need to have minimum 6 characters!");
return false;
} else if (password.getText().toString().trim().length() > 20) {
password.setError("Your password need to have maximum 20 characters!");
return false;
}
return true;
}
to make a button "disabled" You'll need to set it's android:clickable property to false. Then, set a custom background on it that changes its background to gray (or however you want to it look while its disabled). Then after you call that validateData() function you can check to see if you should change the background of the button to be "enabled"
I'm currently working on own implementation of Input Method Editor (IME) or can be called as Softkeyboard in Android, I have read creating an input method and I have downloaded the SoftKeyboard sample code provided as part of the SDK. I have the following code from sample Softkeyboard:
private void handleCharacter(int primaryCode, int[] keyCodes) {
if (isInputViewShown()) {
if (mInputView.isShifted()) {
primaryCode = Character.toUpperCase(primaryCode);
}
}
if (isAlphabet(primaryCode) && mPredictionOn) {
/**
* Swapping here with my desired unicode character
* */
if (primaryCode >= 97 && primaryCode <= 122 ) {
mComposing.append(Swap.swapLetters(primaryCode));
}else{
mComposing.append((char) primaryCode);
}
getCurrentInputConnection().setComposingText(mComposing, 1);
updateShiftKeyState(getCurrentInputEditorInfo());
updateCandidates();
} else {
getCurrentInputConnection().commitText(
String.valueOf((char) primaryCode), 1);
}
}
the code given above works fine, but when I click the key:
<Key android:codes="-1"
android:keyWidth="15%p" android:isModifier="true"
android:isSticky="true" android:keyEdgeFlags="left"/>
which is like Shift key, this converts the keys to uppercase I don't know how to show my next keys this key is clicked/pressed, the following is Logcat of exception:
I have traced that this might be occurring in this place where we handle the Shift key :
private void handleShift() {
if (mInputView == null) {
return;
}
Keyboard currentKeyboard = mInputView.getKeyboard();
if (mQwertyKeyboard == currentKeyboard) {
// Alphabet keyboard
checkToggleCapsLock();
mInputView.setKeyboard(mSindhi);
} else if (currentKeyboard == mSymbolsKeyboard) {
mSymbolsKeyboard.setShifted(true);
mInputView.setKeyboard(mSymbolsShiftedKeyboard);
mSymbolsShiftedKeyboard.setShifted(true);
} else if (currentKeyboard == mSymbolsShiftedKeyboard) {
mSymbolsShiftedKeyboard.setShifted(false);
mInputView.setKeyboard(mSymbolsKeyboard);
mSymbolsKeyboard.setShifted(false);
}
}
now I have not any idea how to get rid of exception mentioned above, and get my code working. please solve this one!
There may be some other solutions for your problem, but I have done one trick and came up with following :
Step-1 You have to remove all the calls to the method updateShiftKeyState(getCurrentInputEditorInfo()); in your code like:
private void handleCharacter(int primaryCode, int[] keyCodes) {
if (isInputViewShown()) {
if (mInputView.isShifted()) {
primaryCode = Character.toUpperCase(primaryCode);
}
}
if (isAlphabet(primaryCode) && mPredictionOn) {
/**
* Swapping here with my desired unicode character
* */
if (primaryCode >= 97 && primaryCode <= 122 ) {
mComposing.append(Swap.swapLetters(primaryCode));
}else{
mComposing.append((char) primaryCode);
}
getCurrentInputConnection().setComposingText(mComposing, 1);
//updateShiftKeyState(getCurrentInputEditorInfo()); // you can delete this method from your class and clean-up all the occurances of that
updateCandidates();
} else {
getCurrentInputConnection().commitText(
String.valueOf((char) primaryCode), 1);
}}
Step-2 change your handleShift method to his:
private void handleShift() {
if (mInputView == null) {
return;
}
Keyboard currentKeyboard = mInputView.getKeyboard();
if (mQwertyKeyboard == currentKeyboard) {
mInputView.setKeyboard(mSindhi);
} else if (currentKeyboard == mSymbolsKeyboard) {
mInputView.setKeyboard(mSymbolsShiftedKeyboard);
} else if (currentKeyboard == mSymbolsShiftedKeyboard) {
mInputView.setKeyboard(mSymbolsKeyboard);
}
}
that is all, Hope this may work for you...
I'm trying to create an app that scans for wifi. When the player does something in the game, it "consumes" the strongest wifi signal. That signal should no longer be detected on the next scan.
Anyone who's played Metal Gear Solid Portable ops would know what I mean.
I tried to do this by creating a List of Wireless Signals that have already been used by the player and can no longer be detected again. The problem is that after scanning the best network, I scan again and it still displays the same network instead of ignoring it.
public void onClick(View arg0) {
if (arg0.getId() == R.id.bStart) {
ActivityLoader.loadMain(this);
}
if (arg0.getId() == R.id.bScan) {
Toast.makeText(this, "Searching....", Toast.LENGTH_LONG).show();
for (ScanResult selectedSpot : networkList) {
{
if (firstSignal == null || checkIfNotUsed(firstSignal)) {
firstSignal = selectedSpot;
usedNetworks.add(firstSignal.SSID);
break;
}
}
}
}
if (firstSignal != null) {
Toast.makeText(
this,
"Found Food and Ammo at the " + firstSignal.SSID
+ " store.", Toast.LENGTH_LONG).show();
// textStatus.setText(usedNetworks.toString());
textStatus.setText(networkList.toString());
} else {
Toast.makeText(this, "Found nothing!!!", Toast.LENGTH_LONG).show();
}
}
private boolean checkIfNotUsed(ScanResult selectedSpot) {
// TODO Auto-generated method stub
boolean flag = true;
if (usedNetworks.isEmpty()) {
flag = true;
} else {
for (String used : usedNetworks) {
if (selectedSpot.SSID.equals(used)) {
flag = false;
break;
}
}
}
return flag;
}